how display balance of token through Ethereum RPC?
$id = 0;
$data = array();
$data[\'jsonrpc\'] = \'2.0\';
$data[\'id\'] = $id++;
$data[\'method\'] = \'eth_call\
When calling a Solidity contract function, in general, data
should be the following, encoded as a hex string:
The function signature for an ERC20 token's balanceOf
is balanceOf(address)
. The keccak-256 hash is 70a08231b98ef4ca268c9cc3f6b4590e4bfec28280db06bb5d45e689f2a360be
, so the first four bytes are 70a08231
.
The function only takes a single parameter: the address of the account whose balance you're trying to look up. To ABI-encode it, simply left-pad it with zeros until it's 32 bytes long. Since addresses are 20 bytes, this means adding 12 bytes of zeros (or 24 characters in hex).
So the full data
field should be "0x70a08231" + "000000000000000000000000" + address
.