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

web3.eth.abi.decodeParameters returns array for one parameter and object for multiple #2848

Closed
Velenir opened this issue May 27, 2019 · 2 comments
Labels
2.x 2.0 related issues Bug Addressing a bug Stale Has not received enough activity

Comments

@Velenir
Copy link
Contributor

Velenir commented May 27, 2019

Description

web3.eth.abi.decodeParameters returns an Object when decoding multiple parameters and an Array when decoding one parameter. In version beta.37 both cases returned Result object

Expected behavior

Like it was in version beta.37:

> const abi = require('web3-eth-abi')
> const encoded = abi.encodeParameters(['string', 'string'], ['Hello', 'World!']);
> encoded
'0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006576f726c64210000000000000000000000000000000000000000000000000000'
> let decoded = abi.decodeParameters(['string', 'string'], encoded);
> decoded
Result { '0': 'Hello', '1': 'World!', __length__: 2 }
> decoded.constructor.name
'Result'
> decoded = abi.decodeParameters(['string'], encoded);
Result { '0': 'Hello', __length__: 1 }
> decoded.constructor.name
'Result'
> 

Actual behavior

> const ABI = require('web3-eth-abi')
> const abi = new ABI.AbiCoder()
> const encoded = abi.encodeParameters(['string', 'string'], ['Hello', 'World!']);
> encoded
'0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006576f726c64210000000000000000000000000000000000000000000000000000'
> let decoded = abi.decodeParameters(['string', 'string'], encoded);
> decoded
{ '0': 'Hello', '1': 'World!' }
> decoded.constructor.name
'Object'
> decoded = abi.decodeParameters(['string'], encoded);
[ 'Hello' ]
> decoded.constructor.name
'Array'

Is it intentional that decoding one parameter returns an array, and multiple -- an object? Would be nice to have decodeParameters return the same in both cases.

Gists

Versions

  • web3.js: 1.0.0-beta.55
  • nodejs: v10.15.3
  • browser: node console
  • ethereum node:
@nivida
Copy link
Contributor

nivida commented May 28, 2019

Thanks for figuring this out! I will fix and release it asap.

@nivida nivida added the Bug Addressing a bug label May 28, 2019
@nivida nivida added the 2.x 2.0 related issues label Jun 20, 2019
@github-actions
Copy link

github-actions bot commented Jul 3, 2020

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment, otherwise this issue will be closed in 7 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x 2.0 related issues Bug Addressing a bug Stale Has not received enough activity
Projects
None yet
Development

No branches or pull requests

2 participants