Code Monkey home page Code Monkey logo

tokenbalance's Introduction

TokenBalance

TokenBalance API Build Status Docker Build Status Coverage Status GoDoc

TokenBalance is an easy to use public API and application that will output your ERC20 Token balance without any troubles. You can run TokenBalance on your local computer or you can use api.tokenbalance.com to easily parse your erc20 token balances. Connects to your local geth IPC and prints out a simple JSON response for ethereum token balances. Runs on port 8080 by default if you wish to run locally.

Server Status and Uptime

You can view the current status of Token Balance along with API latency information on our status page. This status page logs the Ethereum Mainnet, Ropsten testnet, and Rinkeby testnet.

https://status.tokenbalance.com

Installing Token Balance

You don't need to compile Token Balance from source anymore! All you need to do is go to Releases in this repo and download the binary that is built for your OS. Once you've downloaded, rename the file to tokenbalance for ease if use. On Mac or Linux move this file with the command mv tokenbalance /usr/local/bin/tokenbalance, you should be able to run the application from anywhere now.

Token Balance and Token Info (/token)

To fetch information about your balance, token details, and ETH balance use the follow API call in a simple HTTP GET or CURL. The response is in JSON so you can easily parse what you need. Replace TOKEN_ADDRESS with the contract address of the ERC20 token, and replace ETH_ADDRESS with your address.

Ethereum Mainnet
https://api.tokenbalance.com/token/TOKEN_ADDRESS/ETH_ADDRESS
Ethereum Ropsten Testnet
https://test.tokenbalance.com/token/TOKEN_ADDRESS/ETH_ADDRESS
Ethereum Rinkeby Testnet
https://rinkeby.tokenbalance.com/token/TOKEN_ADDRESS/ETH_ADDRESS
  • Response (JSON)
{
    "name": "Kin",
    "wallet": "0x393c82c7Ae55B48775f4eCcd2523450d291f2418",
    "symbol": "KIN",
    "decimals": 18,
    "balance": "15788648",
    "eth_balance": "0.217960852347180212",
    "block": 4274167
}

Only Token Balance (/balance)

This API response will only show you the ERC20 token balance in plain text. Perfect for ultra simple parsing.

https://api.tokenbalance.com/balance/TOKEN_ADDRESS/ETH_ADDRESS
  • Response (PLAIN TEXT)
1022.503000

Examples

Run with Docker

You can easily start Token Balance with Docker. Register for a free Infura.io API Key to use Token Balance without downloading the ethereum blockchain.

docker run -p 8080:8080 -e GETH_SERVER=https://mainnet.infura.io/APIKEY -d hunterlong/tokenbalance

Use as Golang Package

You can use Token Balance as a typical Go Language package if you you like to implement ERC20 functionality into your own application.

go get github.com/hunterlong/tokenbalance
First you'll want to connect to your Geth server or IPC
import (
    "github.com/hunterlong/tokenbalance"
)

func main() {
	// connect to your Geth Server
    configs = &tokenbalance.Config{
         GethLocation: "https://eth.coinapp.io",
         Logs:         true,
    }
    configs.Connect()

    // insert a Token Contract address and Wallet address
    contract := "0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0"
    wallet := "0xbfaa1a1ea534d35199e84859975648b59880f639"

    // query the blockchain and wallet details
    token, err := tokenbalance.New(contract, wallet)

    // Token Balance will respond back useful things
    token.BalanceString()  // "600000.0"
    token.ETHString()      // "1.020095885777777767"
    token.Name             // "OmiseGO"
    token.Symbol           // "OMG"
    token.Decimals         // 18
    token.Balance          // big.Int() (token balance)
    token.ETH              // big.Int() (ether balance)
}

Implement in Google Sheets

If your familiar with Google Sheets, you can easily fetch all of your cryptocurrency balances within 1 spreadsheet. All you need to do is make a cell with the value below.

=ImportData("https://api.tokenbalance.com/balance/0xd26114cd6EE289AccF82350c8d8487fedB8A0C07/0xf9578adc61d07671f536d50afc5800232fc9fd86")

Simple as that! Get creative an use Coin Market Cap's API to fetch the price and multiply with your balance to make a portfolio of your cryptocurrencies!

Implement in your App

Feel free to use the TokenBalance API server to fetch ERC20 token balances and details. We do have a header set that will allow you to call the API via AJAX. Access-Control-Allow-Origin "*" The server may limit your requests if you do more than 60 hits per minute.

Run Your Own Server

TokenBalance isn't just an API, it's an opensource HTTP server that you can run on your own computer or server.

Installation

Ubuntu 16.04
git clone https://github.com/hunterlong/tokenbalance
cd tokenbalance
go get && go build ./cmd

Start TokenBalance Server

tokenbalance start --geth="/ethereum/geth.ipc"

This will create a light weight HTTP server will respond balance information about a ethereum contract token.

Optional Config

tokenbalance start --geth="/ethereum/geth.ipc" --port 8080 --ip 127.0.0.1

CURL Request

CONTRACT=0xa74476443119A942dE498590Fe1f2454d7D4aC0d
ETH_ADDRESS=0xda0aed568d9a2dbdcbafc1576fedc633d28eee9a

curl https://api.tokenbalance.com/token/$CONTRACT/$ETH_ADDRESS

Response

{
    "name": "Kin",
    "wallet": "0x393c82c7Ae55B48775f4eCcd2523450d291f2418",
    "symbol": "KIN",
    "decimals": 18,
    "balance": "15788648",
    "eth_balance": "0.217960852347180212",
    "block": 4274167
}

tokenbalance's People

Contributors

hunterlong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tokenbalance's Issues

bad gateway

looks like the API server is having some problems

image

Lag

We are doing some testing and using the API from TokenBalance.
However the issue we are running into is that it is not updating in a timely manor.

For example, I have transferred 100 PLUM and 20 PLUM, on two separate transactions
but the balance is still only showing 30 PLUM from the previous days transactions.

If I hunt around on other sources, the transaction has already posted and shown.

Curious as to what the timing is for updates on your end.
Thank you!

Contract not found

I get a contract not found at address after running on my machine, debian 10. Any idea how to fix?

Is the server down?

Hello! I built a quick project for a hackathon yesterday and used this great service but now I think the Ropsten endpoint is down? Any way it can be reactivated? Thanks!

balance result different from ethscan

Really appreciate this tool, helped me a lot!

I run tokenbalance in docker.
I found that the erc20 balance result for the same wallet against the same contract is different from the result on ethscan (when decimal is large? result is the same when decimal is 6).
for example:
curl http://localhost:8080/token/0x514910771af9ca656af840dff83e8264ecf986ca/0xdc4252e99397371ada045040a28c05025bae7101

result:
{"token":"0x514910771AF9Ca656af840dff83E8264EcF986CA","wallet":"0xDc4252E99397371aDa045040A28C05025bAE7101","name":"ChainLink Token","symbol":"LINK","balance":"3997863.6130105284973979","eth_balance":"0.0","decimals":18,"block":8711386}

while the balance on ethscan is:
3997863.613010528440330967

Is there any problem when transforming balance, please?

Token Balance API is down

Hello, I wanted to report the API. https://api.tokenbalance.com is down. Getting back a 521 error. Tried from multiple IPs so it doesn't seem to be a problem with proxies.

error "abi: unmarshalling empty output" tokenbalance.New where using as library

I've found that certain token contracts will result in the following error

"abi: unmarshalling empty output"

The following token contracts result in this error

DGD - 0xe0b7927c4af23765cb51314a0e0521a9645f0e2a
LRC - 0xef68e7c694f40c8202821edf525de3782458639f
ICX - 0xb5a5f22694352c15b00323844ad545abb2b11028

// this is how I'm calling the function.
token, err := tokenbalance.New(contract, contract)

The API server is Geth 1.8.17-stable-8bbe7207

I'm currently only interested in the decimal count and symbol information.

Token Balance Issue

This issue is coming for the token balance,when we have following balances in any address like 100,120,2200,1000 it shows 1,12,22,1 respectively on giving the response.

As you can check on this address :
0x0f1cbae928ae3073fad522c8fa902b7ff679d881
https://rinkeby.etherscan.io/token/0x53576813682009a4d35495e18f039067618b3e27#balances
ON GET request https://rinkeby.tokenbalance.com/token/0x53576813682009a4D35495e18f039067618B3e27/0x0f1cbae928ae3073fad522c8fa902b7ff679d881
I am getting token balance : 1 but I have 100 tokens

test.tokenbalance.com missing Allow Origin header

Hello,

From Postman the following request works:

https://test.tokenbalance.com/token/0x3c52896bdd11cb76356b38236978f572333cd188/0x86549A6797F0c1fC7ABF5574dC9916EA57EF2825

But when I'm issuing it from the browser it's being rejected due to CORS.

$("button").click(function() { $("BUTTON").html("Loading"); var token = $("#contract_address").val(); var address = $("#eth_address").val(); $.get("https://test.tokenbalance.com/token/" + token + "/" + address, function(data, status) { $("#token_name").html(data.name); $("#token_amount").html(data.balance + " " + data.symbol); $("#eth_balance").html(data.eth_balance + " ETH"); $("BUTTON").html("Get Balance"); }).catch(function(e) { alert(e.statusText+" - unknown token"); }); });

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://test.tokenbalance.com/token/0x3c52896bdd11cb76356b38236978f572333cd188/0x86549A6797F0c1fC7ABF5574dC9916EA57EF2825. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

API fails with SSL error

An error occurred during a connection to api.tokenbalance.com. Cannot communicate securely with peer: no common encryption algorithm(s). Error code: SSL_ERROR_NO_CYPHER_OVERLAP

ERC20 constant type error

Some Tokens, such as EOS, have different decimal or symbol type, which can cause search error.It may need to be contained.:)

Compile error at bind.NewBoundContract

trying to compile:

/usr/lib/go-1.9/bin/go get

github.com/hunterlong/tokenbalance

./tokens.go:104:30: not enough arguments in call to bind.NewBoundContract
have (common.Address, abi.ABI, bind.ContractCaller, bind.ContractTransactor)
want (common.Address, abi.ABI, bind.ContractCaller, bind.ContractTransactor, bind.ContractFilterer)

root@geth1:~/go/src/github.com/hunterlong/tokenbalance# /usr/lib/go-1.9/bin/go version
go version go1.9.2 linux/amd64

Thanks

Cannot use 'out' (type **big.Int) as the type *[]interface{}

err := _Token.contract.Call(opts, out, "balanceOf", _owner)

# github.com/hunterlong/tokenbalance
../../../../hunterlong/tokenbalance/tokens.go:94:29: cannot use out (type **big.Int) as type *[]interface {} in argument to _Token.contract.Call
../../../../hunterlong/tokenbalance/tokens.go:106:29: cannot use out (type **big.Int) as type *[]interface {} in argument to _Token.contract.Call
../../../../hunterlong/tokenbalance/tokens.go:118:29: cannot use out (type *string) as type *[]interface {} in argument to _Token.contract.Call
../../../../hunterlong/tokenbalance/tokens.go:130:29: cannot use out (type *string) as type *[]interface {} in argument to _Token.contract.Call

Can you fix these places ?

Build failed.

The build log:

go get -u github.com/hunterlong/tokenbalance
# github.com/hunterlong/tokenbalance
src/github.com/hunterlong/tokenbalance/tokens.go:94:29: cannot use out (type **big.Int) as type *[]interface {} in argument to _Token.contract.Call
src/github.com/hunterlong/tokenbalance/tokens.go:106:29: cannot use out (type **big.Int) as type *[]interface {} in argument to _Token.contract.Call
src/github.com/hunterlong/tokenbalance/tokens.go:118:29: cannot use out (type *string) as type *[]interface {} in argument to _Token.contract.Call
src/github.com/hunterlong/tokenbalance/tokens.go:130:29: cannot use out (type *string) as type *[]interface {} in argument to _Token.contract.Call
$ go version
go version go1.14.12 linux/amd64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.