Class: CronosExplorer::Accounts

Inherits:
Object
  • Object
show all
Defined in:
lib/cronos_explorer/accounts.rb

Constant Summary collapse

DEFAULT_HASH =
{ module: 'account' }.freeze

Class Method Summary collapse

Class Method Details

.balance(address) ⇒ Object

Get balance for address. Also available through a GraphQL ‘addresses’ query.

If the balance hasn't been updated in a long time, 
we will double check with the node to fetch the absolute latest balance. 
This will not be reflected in the current request, but once it is updated, 
subsequent requests will show the updated balance. 
If you want to know whether or not we are checking for another balance, use the `balancemulti` action. 
That contains a property called `stale` that will let you know to recheck that balance in the near future.


24
25
26
27
28
# File 'lib/cronos_explorer/accounts.rb', line 24

def balance(address)
  hash = DEFAULT_HASH.merge(action: 'balance', address: address)

  Request.get hash
end

.eth_get_balance(address) ⇒ Object

Mimics Ethereum JSON RPC’s eth_getBalance. Returns the balance as of the provided block (defaults to latest)



9
10
11
12
13
# File 'lib/cronos_explorer/accounts.rb', line 9

def eth_get_balance(address)
  hash = DEFAULT_HASH.merge(action: 'eth_get_balance', address: address)

  Request.get hash
end

.tokenbalance(contractaddress, address) ⇒ Object

Get token account balance for token contract address.



45
46
47
48
49
# File 'lib/cronos_explorer/accounts.rb', line 45

def tokenbalance(contractaddress, address)
  hash = DEFAULT_HASH.merge(action: 'tokenbalance', contractaddress: contractaddress, address: address)

  Request.get hash
end

.tokenlist(address) ⇒ Object

Get list of tokens owned by address.



52
53
54
55
56
# File 'lib/cronos_explorer/accounts.rb', line 52

def tokenlist(address)
  hash = DEFAULT_HASH.merge(action: 'tokenlist', address: address)

  Request.get hash
end

.tokentx(address, startblock, sort = 'desc') ⇒ Object

Get token transfer events by address. Up to a maximum of 10,000 token transfer events. Also available through a GraphQL ‘token_transfers’ query.



38
39
40
41
42
# File 'lib/cronos_explorer/accounts.rb', line 38

def tokentx(address, startblock, sort='desc')
  hash = DEFAULT_HASH.merge(action: 'tokentx', address: address, startblock: startblock, sort: sort)

  Request.get hash
end

.txlist(address, starttimestamp = nil, sort = 'desc') ⇒ Object

Get transactions by address. Up to a maximum of 10,000 transactions. Also available through a GraphQL ‘address’ query.



31
32
33
34
35
# File 'lib/cronos_explorer/accounts.rb', line 31

def txlist(address, starttimestamp = nil, sort = 'desc')
  hash = DEFAULT_HASH.merge(action: 'txlist', address: address, starttimestamp: starttimestamp, sort: sort)

  Request.get hash
end