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

Bug with ethGetBalance in the EmbeddedWeb3jService #88

Open
bbertolucci opened this issue Sep 29, 2022 · 0 comments
Open

Bug with ethGetBalance in the EmbeddedWeb3jService #88

bbertolucci opened this issue Sep 29, 2022 · 0 comments

Comments

@bbertolucci
Copy link

bbertolucci commented Sep 29, 2022

There is a bug in the manner of setting the result of ethGetBalance in the EmbeddedWeb3jService.kt

I tested on an alchemy ethereum branch :

val balance = web3j.ethGetBalance(accountAddress, DefaultBlockParameterName.LATEST).send()

And I got the result :
image

Now I tested the same code on embedded service and got :
image

The difference is coming from the 0 prefixing the value 0x 00000000000 ....
The object return is an EthGetBalance object with a getBalance()
getBalance will use Numeric.decodeQuantity(getResult())
Well I will not write all the details but it checks the validity of the string.
You can see the code here
One of the test is : value.length() > 3 && value.charAt(2) == '0'
So the value is incorrect and will return an Exception when having 0 following 0x

The error is coming from this code :
https://github.com/web3j/web3j-evm/blob/a40b044df37a0c3426dc24f71589b03327b3a8bc/src/main/kotlin/org/web3j/evm/EmbeddedEthereum.kt#L219-L227

and
https://github.com/web3j/web3j-evm/blob/a40b044df37a0c3426dc24f71589b03327b3a8bc/src/main/kotlin/org/web3j/evm/EmbeddedWeb3jService.kt#L220-L230

.map(Wei::toHexString) will add all those 0
The solution is to use: .map(Wei::toShortHexString) (Edit : Tested with success !!)

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

1 participant