Get token balance with Ethereum RPC?

前端 未结 4 1967
遥遥无期
遥遥无期 2021-02-06 13:38

how display balance of token through Ethereum RPC?

$id = 0;
$data = array();
$data[\'jsonrpc\'] = \'2.0\';
$data[\'id\'] = $id++;
$data[\'method\'] = \'eth_call\         


        
4条回答
  •  有刺的猬
    2021-02-06 13:43

    May I recommend a proper ERC20 library for PHP that I have developed myself.

    https://www.furqansiddiqui.com/libraries/erc20-php/

    https://github.com/furqansiddiqui/erc20-php

    sample code to retrieve balance:

    token('0xd26114cd6EE289AccF82350c8d8487fedB8A0C07');
    
    var_dump($token->name()); # string(8) "OMGToken"
    var_dump($token->symbol()); # string(3) "OMG"
    var_dump($token->decimals()); # int(18)
    
    var_dump($token->balanceOf('0x...')); // Enter ethereum address here
    

提交回复
热议问题