Comments (5)
Hi,
Big numbers are true pain. Doesn't handle decimals. When transforming to bigger units, where divisions can produce decimals, big number returns an array of [quotient, remainder], not a "simple" big number.
Transforming toEther and fromWei is very delicate for this reason. That's why I added the xxxString versions, that return a "human readable" amount. All math involving BigNumbers has to be done in weis. Transformation to bigger units are only for user's I/O.
As for your example:
40432342326000000000000
transforms to 0x88FD777A5C42D216000
in hex (online hex converter)
This code:
$bn1 = Utils::hexToBn("0x88FD777A5C42D216000");
echo $bn1 . " ";
echo Utils::fromWeiToString($bn1, "ether") . " ";
echo Utils::toEtherString($bn1, "wei") . " ";
Prints as expected:
40432342326000000000000 40432.342326000000000000 40432.342326000000000000
from simple-web3-php.
Thanks for the clarification but I think that's not exactly the point.
When I use the explorer, the contract tells me :
int256: 40371499598000000000000
Which is the real expected answer.
But when I call from SWeb3 the contract, the raw answer given is :
0x88c8b1adb02476ae0000
Which would give us according to your conversion table :
645943993568000000000000
By doing $sweb3->utils->hexToBn("0x88c8b1adb02476ae0000")
, I get :
0x0088c8b1adb02476ae0000
Which would also give us according to your conversion table:
645943993568000000000000
Concerning the toString function $sweb3->utils->toEtherString("0x88c8b1adb02476ae0000", "wei")
:
645943.993568000000000000
So I don't understand how to find the expected result, indeed I want to find the same value as int256 from the retrieved GN, not the other way around.
from simple-web3-php.
Ok,
Then the problem is at the decoding step of the call function.
Can you paste here an example contract where this happens? I would help a lot.
Btw, I'm testing it on the main-dev branch. It has some improvements in the ABI decoder... So the example code can help me to find the problem.
from simple-web3-php.
Ok,
Then the problem is at the decoding step of the call function.
Can you paste here an example contract where this happens? I would help a lot.
Btw, I'm testing it on the main-dev branch. It has some improvements in the ABI decoder... So the example code can help me to find the problem.
https://optimistic.etherscan.io/address/0x82ac2CE43e33683c58BE4cDc40975E73aA50f459#readProxyContract#F3
from simple-web3-php.
Thanks for pointing me in the right direction.
There was a bug in the ABI decoder, when decoding signed integers. When the left hex character was >= 8 (most significant bit was 1), the ABI decoder treated it as a negative number.
It should be fixed on the next update (main-dev branch).
For the record, I used this test contract to test some cases:
pragma solidity >=0.7.0 <0.9.0;
contract Test
{
int256 public a;
uint256 public a_unsigned;
int256 public b;
int256 public c;
//CONSTRUCTOR
constructor()
{
a = 40371499598000000000000;
a_unsigned = 40371499598000000000000;
b = -1;
c = 4503599627370495;
}
//CALL (GETTERS)
function getValue_a() public view returns (int256)
{
return a;
}
function getValue_a_unsigned() public view returns (uint256)
{
return a_unsigned;
}
function getValue_b() public view returns (int256)
{
return b;
}
function getValue_c() public view returns (int256)
{
return c;
}
}
from simple-web3-php.
Related Issues (20)
- Leading zero in address trimmed HOT 1
- 2 Bugs in encoding tuples ( Incorrect assumption that tuple is always dynamic ) ? HOT 3
- Split ABIv2 encoding/decoding HOT 1
- substr(): Argument #3 ($length) must be of type ?int, float given HOT 3
- Add blockTag to the SWeb3_Contract.php HOT 1
- why is there a memory shortage during the Call contract command? HOT 1
- The output data of the read contract command is missing [solved] HOT 7
- can I get the Latest 25 BEP-20 Token Transfer Events on a specified contract through Simple-Web3-Php? HOT 2
- how to call the interface functions of contract? HOT 1
- How to query the number of Token holdings on a specified contract? [Solved] HOT 7
- Stargate finance tuple issue HOT 1
- Please upgrade kornrunner/ethereum-offline-raw-tx ^0.4.0 to ^0.6.0
- Seems fixed size array inside struct (tuple) breaks encoding. HOT 2
- How to obtain correct bytes32 string? HOT 2
- ABI Encoding, Keccak256 Hashing HOT 2
- Error sending wallet address different from contract HOT 3
- unable to decode data via DecodeData method HOT 1
- Core/ABI->GetEventFromHash throws exception on invalid index. HOT 1
- Custom blockchain ID HOT 1
- How to use that library in a server without Composer?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-web3-php.