Add decode function parameters
Is there an existing issue for this?
- [X] I have searched the existing issues
Feature Request
https://github.com/ChainSafe/web3.js/issues/3016
See here https://github.com/ChainSafe/web3.js/issues/3016#issuecomment-828274902
In reference to the this problem people have, decoding a function requires removing the first 8 characters after the 0x.
Adding a decodeFunctionParameters method would solve this, simply by splicing the first 8 characters after the 0x and returning the parameters.
Use Cases
Used in getting the returned parameter data of function calls.
Stops people from being confused about why decodeParameters is not working.
Implementation Ideas
No response
Feature Examples/References
Ugly example, but it works to prove the point.
let web3 = new Web3('https://bsc-dataseed.binance.org/');
const a = await web3.eth.getTransaction('0x041e65ab1b3ef192d1e2ae38d167f6293f026b20da980f4987e173c9ffcfc886');
let find = a.input.slice(2, 10); <--- Slice the 8 characters out of the hex
let remove = a.input.replace(find, ''); <--- Remove the 8 characters
const z = await web3.eth.abi.decodeParameters(
[
{
type: 'address',
name: 'token',
},
{
type: 'uint256',
name: 'amount',
},
{
type: 'address',
name: 'receiverAddress',
},
{
type: 'uint256',
name: 'targetChainId',
}
],
remove <--- Hex with function ID removed
);
let remove = `0x${a.input.substr(10)}`; <---- Remove the function ID, add back in the 0x
const z = await web3.eth.abi.decodeParameters(
[
{
type: 'address',
name: 'token',
},
{
type: 'uint256',
name: 'amount',
},
{
type: 'address',
name: 'receiverAddress',
},
{
type: 'uint256',
name: 'targetChainId',
}
],
remove
);
web3.eth.abi.decodeFunctionParameters([<PARAMETERS>], string)
Final output is CORRECT data.
Are you willing to implement this feature?
- [x] Yes
@defido Thanks, The best place to implement this will be our 4.x.
@defido Thanks for reaching out to us. I think that will be a nice feature but we will plan it for future releases in 4.x. You are welcomes to contribute this feature for 4.x branch.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.