Class: Klaytn::Wallet
Constant Summary collapse
- BASE_URL =
'https://api-cypress-v2.scope.klaytn.com/v2/accounts'.freeze
- PEB_DIVISOR =
friendly ‘get_balance’ result, ex: “5” == 5 KLAY
1000000000000000000.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
-
#divisor ⇒ Object
readonly
Returns the value of attribute divisor.
Attributes inherited from Client
#basic_auth, #chain_id, #contract_address
Instance Method Summary collapse
- #get(address) ⇒ Object
- #get_balance(address) ⇒ Object
- #headers ⇒ Object
-
#initialize(peb_divisor: true) ⇒ Wallet
constructor
no params needed, overrides Klaytn::Client.
Methods inherited from Client
#setup_basic_auth, #setup_chain_id
Constructor Details
#initialize(peb_divisor: true) ⇒ Wallet
no params needed, overrides Klaytn::Client
9 10 11 |
# File 'lib/klaytn/wallet.rb', line 9 def initialize(peb_divisor: true) @divisor = peb_divisor ? PEB_DIVISOR : 1 end |
Instance Attribute Details
#divisor ⇒ Object (readonly)
Returns the value of attribute divisor.
6 7 8 |
# File 'lib/klaytn/wallet.rb', line 6 def divisor @divisor end |
Instance Method Details
#get(address) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/klaytn/wallet.rb', line 13 def get(address) resp = HTTParty.get(BASE_URL + "/#{address}", headers: headers) data = JSON.parse(resp.body) rescue => e raise e. end |
#get_balance(address) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/klaytn/wallet.rb', line 20 def get_balance(address) data = get(address) data.dig('result', 'balance').to_f / divisor rescue => e raise e. end |
#headers ⇒ Object
27 28 29 |
# File 'lib/klaytn/wallet.rb', line 27 def headers { origin: 'https://scope.klaytn.com' } end |