Skip to content

bep20 failed to obtain balance #24

@leo98123

Description

@leo98123

my code:
$apiKey = 'my apikey************';
$api = new \Binance\BscscanApi($apiKey);
$config = [
'contract_address' => '0x55d398326f99059fF775485246999027B3197955',// USDT BEP20
'decimals' => 18,
];
$address = '0xA3E043CA89B6dA1ae800a4816ff22afea1e2cAcf';
$bep20 = new \Binance\BEP20($api, $config);
$usdtBalance = $bep20->balance($address);
echo $usdtBalance;

My code is as above. No matter which address is filled in, the return is 0.000000014. I entered the code debugging and found that BEP20.PHP
method:
public function balance(string $address)
{
$params = [];
$params['to'] = $this->contractAddress;
$method = 'balanceOf(address)';
$formatMethod = Formatter::toMethodFormat($method);
$formatAddress = Formatter::toAddressFormat($address);

$params['data'] = "0x{$formatMethod}{$formatAddress}";
$balance = $this->proxyApi->ethCall($params);
echo "ethCall Response: " . json_encode($balance) . "
";
return Utils::toDisplayAmount($balance, $this->decimals);
}
The debugging result is:
ethCall Response: "Error!"

I don't know what went wrong now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions