web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Add decode function parameters

Open defido opened this issue 3 years ago • 7 comments

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 avatar Apr 04 '22 03:04 defido

@defido Thanks, The best place to implement this will be our 4.x.

jdevcs avatar Apr 04 '22 16:04 jdevcs

@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.

nazarhussain avatar Apr 06 '22 10:04 nazarhussain

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.

github-actions[bot] avatar Jun 06 '22 00:06 github-actions[bot]

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.

github-actions[bot] avatar Aug 16 '22 00:08 github-actions[bot]

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.

github-actions[bot] avatar Oct 31 '22 00:10 github-actions[bot]

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.

github-actions[bot] avatar Jan 01 '23 00:01 github-actions[bot]

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.

github-actions[bot] avatar Mar 04 '23 00:03 github-actions[bot]