tokenbalance: github.com/hunterlong/tokenbalance Index | Examples | Files | Directories

package tokenbalance

import "github.com/hunterlong/tokenbalance"

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/hunterlong/tokenbalance

Index

Examples

Package Files

doc.go tokenbalance.go tokens.go types.go

Variables

var (
    Geth *ethclient.Client

    VERSION string
)

type Config Uses

type Config struct {
    GethLocation string
    Logs         bool
}

func (*Config) Connect Uses

func (c *Config) Connect() error

type TokenBalance Uses

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 Uses

func New(contract, wallet string) (*TokenBalance, error)

Create a New Token Balance request with the ERC20 contract address and a wallet address

Code:

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 Uses

func (tb *TokenBalance) BalanceString() string

Return the Token Balance as a string rather than a *big.Int

Code:

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 Uses

func (tb *TokenBalance) ETHString() string

Return the ETH Balance as a string rather than a *big.Int

Code:

eth := example.ETHString()
fmt.Printf("This wallet has %v ETH", eth)

Output:

This wallet has 0.277525175999999985 ETH

func (*TokenBalance) ToJSON Uses

func (tb *TokenBalance) ToJSON() string

View all token information as JSON

Code:

data := example.ToJSON()
fmt.Println(data)

Directories

PathSynopsis
cmdPackage main inside the cmd folder contains TokenBalance binary file for your operating system

Package tokenbalance imports 12 packages (graph) and is imported by 2 packages. Updated 2018-11-22. Refresh now. Tools for package owners.