Class: Klaytn::Token

Inherits:
Client show all
Defined in:
lib/klaytn/token.rb

Constant Summary collapse

BASE_URL =
'https://th-api.klaytnapi.com/v2/contract/nft'.freeze

Constants inherited from Base

Base::FUNCTION_NOT_FOUND, Base::INVALID_CLIENT, Base::MISSING_ABI, Base::MISSING_ACCOUNT_POOL_KRN, Base::MISSING_ACCOUNT_WALLET, Base::MISSING_CONTRACT, Base::MISSING_JSONRPC_METHOD, Base::MISSING_KAS_CREDS

Instance Attribute Summary collapse

Attributes inherited from Client

#basic_auth, #chain_id, #contract_address, #headers

Instance Method Summary collapse

Methods inherited from Client

#setup_basic_auth, #setup_chain_id

Constructor Details

#initialize(opts = {}) ⇒ Token

Returns a new instance of Token.

Raises:



7
8
9
10
11
12
# File 'lib/klaytn/token.rb', line 7

def initialize(opts = {})
  raise MISSING_CONTRACT if opts[:contract_address].blank?

  @encoder = Encoder.new
  super
end

Instance Attribute Details

#encoderObject (readonly)

Returns the value of attribute encoder.



5
6
7
# File 'lib/klaytn/token.rb', line 5

def encoder
  @encoder
end

Instance Method Details

#encoded_token_id(token_id) ⇒ Object



20
21
22
# File 'lib/klaytn/token.rb', line 20

def encoded_token_id(token_id)
  encoder.encode_integer(token_id)
end

#get(token_id) ⇒ Object



14
15
16
17
18
# File 'lib/klaytn/token.rb', line 14

def get(token_id)
  url = BASE_URL + "/#{contract_address}/token/#{encoded_token_id(token_id)}"
  resp = HTTParty.get(url, headers: headers, basic_auth: basic_auth)
  JSON.parse(resp.body)
end