-
-
Notifications
You must be signed in to change notification settings - Fork 26
Description
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()Now I tested the same code on embedded service and got :

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
.map(Wei::toHexString) will add all those 0
The solution is to use: .map(Wei::toShortHexString) (Edit : Tested with success !!)
