web3p / web3.php

A php interface for interacting with the Ethereum blockchain and ecosystem. Native ABI parsing and smart contract interactions.
MIT License
1.16k stars 543 forks source link

Incorrect values returned by contract call #269

Open lwazidp opened 2 years ago

lwazidp commented 2 years ago

My requests are working perfectly but I'm receiving some strange values back.

First of all the function should return a uint256 but i receive an array and second the values are incorrect.

My code:

$web3 = new Web3(new HttpProvider(new HttpRequestManager($provider, 1)));
$abi = '[{"inputs":[],"name":"getTotalDividendsDistributed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]';

$contract = new Contract($web3->provider, $abi);
$contract->at($address)->call("getTotalDividendsDistributed", function ($err, $total) {
    if ($err !== null) {
      dd($err);
    } else {
      dd($total);
    }
});

Returned value:

{
   "value":[
      850193091,
      1882330983
   ],
   "is_negative":false,
   "precision":-1,
   "bitmask":false,
   "hex":null
}

But checking on Bscscan the value should be: 4042275006966459075

Anyone able to explain what's going on?

sc0Vu commented 2 years ago

That's BigInteger from phpseclib, try $total->toString().

https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Math/BigInteger.php