Documentation ¶
Overview ¶
Package tokenbalance is used to fetch the latest token balance for any Ethereum address and ERC20 token. You can install this package/CLI or you can use basic HTTP GET on the public TokenBalance server.
Mainnet API Endpoint: https://api.tokenbalance.com
Example: https://api.tokenbalance.com/balance/0xa74476443119A942dE498590Fe1f2454d7D4aC0d/0xda0aed568d9a2dbdcbafc1576fedc633d28eee9a Response: `5401731.086778292432427406`
Example: https://api.tokenbalance.com/token/0xa74476443119A942dE498590Fe1f2454d7D4aC0d/0xda0aed568d9a2dbdcbafc1576fedc633d28eee9a Response: ``` { "token": "0xa74476443119A942dE498590Fe1f2454d7D4aC0d", "wallet": "0xda0AEd568D9A2dbDcBAFC1576fedc633d28EEE9a", "name": "Golem Network token", "symbol": "GNT", "balance": "5401731.086778292432427406", "eth_balance": "0.985735366999999973", "decimals": 18, "block": 6461672 } ```
Ropsten Testnet API Endpoint: https://test.tokenbalance.com
Rinkeby Testnet API Endpoint: https://rinkeby.tokenbalance.com
More info on: https://github.com/mobazha/tokenbalance
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( Geth *ethclient.Client VERSION string )
Functions ¶
This section is empty.
Types ¶
type TokenBalance ¶
type TokenBalance struct { Contract common.Address Wallet common.Address Name string Symbol string Balance *big.Int ETH *big.Int Decimals int64 Block int64 // contains filtered or unexported fields }
func New ¶
func New(contract, wallet string) (*TokenBalance, error)
Example ¶
Create a New Token Balance request with the ERC20 contract address and a wallet address
token := "0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac" wallet := "0x9ea0c535b3eb166454c8ccbaba86850c8df3ee57" example, _ = New(token, wallet) fmt.Printf("This wallet has %v %v tokens", example.BalanceString(), example.Name)
Output: This wallet has 7.282 StorjToken tokens
func (*TokenBalance) BalanceString ¶
func (tb *TokenBalance) BalanceString() string
Example ¶
Return the Token Balance as a string rather than a *big.Int
tokens := example.BalanceString() fmt.Printf("This wallet has %v %v tokens", tokens, example.Name)
Output: This wallet has 7.282 StorjToken tokens
func (*TokenBalance) ETHString ¶
func (tb *TokenBalance) ETHString() string
Example ¶
Return the ETH Balance as a string rather than a *big.Int
eth := example.ETHString() fmt.Printf("This wallet has %v ETH", eth)
Output: This wallet has 0.277525175999999985 ETH
func (*TokenBalance) ToJSON ¶
func (tb *TokenBalance) ToJSON() string
Example ¶
View all token information as JSON
data := example.ToJSON() fmt.Println(data)
Output: