-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Decode function call #3016
Comments
This error occurs because you're calling the Example: const result = web3.eth.abi.encodeFunctionCall({
name: 'myMethod',
type: 'function',
inputs: [{
type: 'uint256',
name: 'myNumber'
},{
type: 'string',
name: 'myString'
}]
}, ['2345675643', 'Hello!%']);
web3.eth.abi.decodeParameters(['uint256', 'string'], result) |
@nivida thanks for getting back to me. the code you provided still throws the same exact error. |
Hey I just came across a similar error half-asleep last night. I figured it out this morning so I'll share the answer in case someone needs it. @jgeary was encoding a function call and decoding only the argument. Function calls are composed by the function ID (first 4 bytes/8 characters) and then the concatenated parameters. TLDR just slicing off the first 8 chars from the call data should do what you're looking for. _web3.eth.abi.decodeParameters(['uint256', 'string'], '0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000')
// > {0: "2345675643", 1: "Hello!%" } |
Can confirm that what @sterlu wrote is the way to go. Just slice the function signature out of the transaction input. |
Big thanks @sterlu!!! 😎 |
sterlu For others, this is an ugly solution, but it works: (There is 1000 better ways to remove characters from a string in JS)
OPTION 2:
|
Description
I cannot figure out how to decode the result of
web3.eth.abi.encodeFunctionCall(...)
to get the original parameters. Not sure if this is due to lacking functionality or if this is possible but not yet documented.Expected behavior
After calling
and getting the result
"0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000"
,I want to call
web3.eth.abi.decodeParameters(['bytes4', 'uint256', 'string'], result)
to get an array which includes'2345675643'
and'Hello!%'
.Actual behavior
'Uncaught Error: overflow (operation="setValue", fault="overflow", details="Number can only safely store up to 53 bits")'
Versions
The text was updated successfully, but these errors were encountered: