Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$contract->at($erc20TokenAddress)->call('balanceOf', [$accountAddress], function($err, $result) { } function call with params giving error while function call without params is working #354

Open
wtmit opened this issue Apr 26, 2024 · 2 comments

Comments

@wtmit
Copy link

wtmit commented Apr 26, 2024

provider, $erc20TokenABI); $contract->at($erc20TokenAddress)->call('symbol', function ($err, $result) { if ($err !== null) { return; } echo 'The symbol: ' . $result[0]; }); $contract->at($erc20TokenAddress)->call('balanceOf', [$accountAddress], function($err, $result) { if ($err !== null) { echo 'Error: ' . $err->getMessage() . PHP_EOL; // return; } // Print balance print_r($result); }); The symbol: WTM PHP Warning: Array to string conversion in D:\xampp\htdocs\web3.php-master\src\Contracts\Types\Address.php on line 63 Warning: Array to string conversion in D:\xampp\htdocs\web3.php-master\src\Contracts\Types\Address.php on line 63 PHP Fatal error: Uncaught InvalidArgumentException: Please make sure you have put all function params and callback. in D:\xampp\htdocs\web3. .php-master\src\Contract.php:625
@wtmit
Copy link
Author

wtmit commented Apr 26, 2024

$erc20TokenBalance = $contract->at($erc20TokenAddress)->call('balanceOf', [$accountAddress], function($err, $result) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage() . PHP_EOL;
// return;
}

    print_r($result);
        });

@wenzhuangz
Copy link

Try this:
$contract = new Contract(rpcurl, abi);

    $contract->at(tokenAddress)->call('balanceOf', address, [
        'from' => address,
    ], function ($err, $result) use ($contract) {
        if ($err !== null) {
            $this->res['err'] = $err->getMessage();
        }
        if (isset($result)) {;
            $bn = Utils::toBn($result[0]);
            $this->res['amount'] = bcdiv($bn->toString(), 10 ** 18, 18);
        }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants