I'm trying to get the balance of a token on an Ethereum address. So let's say my Ethereum address has 1 SNT. I'd like to make a call to get that 1 SNT as a response. I've written many other calls and can't seem to find or figure out this one. I've tried using the method "eth_call" and using the balanceOf method. I was thinking I could use this method in the contract of the ERC20 token:
function balanceOf(address _owner) constant returns (uint256 balance);
I tried setting the to as the token address, the data as the code for balanceOf, and my wallet address also in the data, but that always returns me 0.
payload = {
"id": 123,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"data": "0xf7888aec000000000000000000000000" + walletAddress_With0xRemoved,
"to": tokenAddress
},
"latest"
]
}
I found this site which has an API, but i'd really like to do it the right way rather than using a wrapper API.
CONTRACT=0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7
ETH_ADDRESS=0x198ef1ec325a96cc354c7266a038be8b5c558f67
curl https://api.tokenbalance.com/balance/$CONTRACT/$ETH_ADDRESS
{
"name": "Golem Network Token",
"wallet": "0xda0aed568d9a2dbdcbafc1576fedc633d28eee9a",
"symbol": "GNT",
"balance": 7.998173814269688,
"eth_balance": 0.9912952230000018,
"decimals": 18,
"block": 3461147
}
Edit: I just realized this website has source code available, haha. Though this isn't the type of ethereum programming i'm used to (Go).