ETHContract v0.2.9 EthContract behaviour

Provides a few convenience methods for getting information about tokens from ETH smart contracts. Uses JSON-RPC for requests.

Link to this section Summary

Functions

Get the account balance given a wallet address

Get the balance given a wallet address. This was tested against ERC20 and ERC721 standard contracts

Decodes general smart contract calls

Decodes events with no indexes

ERC721 Meta. This will return a Map with the meta information associated with a token. You have to provide the name of the method to use (ie. CryptoKitties uses getKitty)

Get the wallet address given a contract and a token id

Parses abi into a map with the name of the method as key

Get the total supply given a contract address. This was tested against ERC20 and ERC721 standard contracts

Link to this section Functions

Link to this function account_balance(map)

Get the account balance given a wallet address.

Link to this function balance_of(map)

Get the balance given a wallet address. This was tested against ERC20 and ERC721 standard contracts.

Examples

iex> EthContract.balance_of(%{address: '0x123', contract: '0x234'})
2
Link to this function decode_data(data, abi, method, signatures_key \\ "inputs")

Decodes general smart contract calls

Link to this function decode_log(data, topics, abi, method)

Decodes events with no indexes.

ERC721 Meta. This will return a Map with the meta information associated with a token. You have to provide the name of the method to use (ie. CryptoKitties uses getKitty)

Examples

iex> abi = EthContract.parse_abi(“test/support/crypto_kitties.json”) iex> EthContract.meta(%{token_id: 45, method: “getKitty”, contract: “0x06012c8cf97BEaD5deAe237070F9587f8E7A266d”, abi: abi}) %{ “birthTime” => 1511417999, “cooldownIndex” => 0, “generation” => 0, “genes” => 626837621154801616088980922659877168609154386318304496692374110716999053, “isGestating” => false, “isReady” => true, “matronId” => 0, “nextActionAt” => 0, “sireId” => 0, “siringWithId” => 0 }

Get the wallet address given a contract and a token id

Examples

iex> EthContract.owner_of(%{token_id: 1, contract: "0x06012c8cf97bead5deae237070f9587f8e7a266d"})
0x79bd592415ff6c91cfe69a7f9cd091354fc65a18
Link to this function parse_abi(file_path)

Parses abi into a map with the name of the method as key.

Examples

iex> abi = EthContract.parse_abi(“test/support/crypto_kitties.json”) %{}

Link to this function total_supply(map)

Get the total supply given a contract address. This was tested against ERC20 and ERC721 standard contracts.

Examples

iex> EthContract.total_supply(%{contract: ‘0x234’}) :ok

Link to this section Callbacks

Link to this callback balance_of(map)
balance_of(map()) :: map()
Link to this callback decode_data(data, abi, method, signatures_key)
decode_data(
  data :: String.t(),
  abi :: String.t(),
  method :: String.t(),
  signatures_key :: String.t()
) :: map()
Link to this callback decode_log(data, topics, abi, method)
decode_log(
  data :: String.t(),
  topics :: String.t(),
  abi :: String.t(),
  method :: String.t()
) :: map()
Link to this callback meta(map)
meta(map()) :: map()
Link to this callback owner_of(map)
owner_of(map()) :: map()
Link to this callback parse_abi(file_path)
parse_abi(file_path :: String.t()) :: map()
Link to this callback total_supply(map)
total_supply(map()) :: map()