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

Problem with decoding complex types returned from contract function #2607

Closed
adammalczewski opened this issue Mar 29, 2019 · 5 comments · Fixed by #2624
Closed

Problem with decoding complex types returned from contract function #2607

adammalczewski opened this issue Mar 29, 2019 · 5 comments · Fixed by #2624
Labels
Bug Addressing a bug

Comments

@adammalczewski
Copy link

Description

I am trying to call a method from blockchain contract which returns single value of type tuple[]:

    const web3 = new Web3(ProviderAddress);
    const contract = new web3.eth.Contract(Web3ContractABI, ContractAddress);
    const users = await contract.methods.getAllUsers().call();

part of ABI JSON regarding getAllUsers function:

  {
    'constant': true,
    'inputs': [],
    'name': 'getAllUsers',
    'outputs': [
      {
        'components': [
          {
            'name': 'idUser',
            'type': 'address'
          },
          {
            'name': 'param1',
            'type': 'int256'
          },
          {
            'name': 'param2',
            'type': 'int256'
          }
        ],
        'name': '',
        'type': 'tuple[]'
      }
    ],
    'payable': false,
    'stateMutability': 'view',
    'type': 'function'
  },

on remix.ethereum.org when i call the function i get:

0: tuple(address,int256,int256)[]: 0xf2D38fC631d4FCFbAeDB274D2b95C436ab75a1B4,0,0

Expected behavior

users should be [["0xf2D38fC631d4FCFbAeDB274D2b95C436ab75a1B4", ...]]

Actual behavior

users is [[]]

Additional notes

I have already found the source of this error, will create PR soon.

Versions

  • web3.js: 1.0.0-beta.51
  • nodejs: 10.14.2
  • ethereum node - instance: Geth/v1.8.16-stable-477eb093/linux-amd64/go1.11, private network
@nivida
Copy link
Contributor

nivida commented Mar 29, 2019

Web3.js is using the AbiCoder of ethers.js. Could you please open an issue in the ethers.js repository?

@nivida nivida closed this as completed Mar 29, 2019
@adammalczewski
Copy link
Author

Web3.js is using the AbiCoder of ethers.js. Could you please open an issue in the ethers.js repository?

I am confident that the problem lies on the Web3.js side and as I have written i have already fixed this, AbiCoder from ethers.js works correctly.

@nivida
Copy link
Contributor

nivida commented Mar 29, 2019

Can you explain to me closer why it should be a problem with Web3.js?

@adammalczewski
Copy link
Author

Method afterExecution in class CallContractMethod in web3-eth-contract/src/methods/CallContractMethod.js passes string to AbiCoder's method decodeParameter instead of AbiOutput and because of this, information about tuple's components is lost.

Now it's:

return this.abiCoder.decodeParameter(outputs[0].type, response);

instead of:

return this.abiCoder.decodeParameter(outputs[0], response);

I fixed this in my fork already but I'm still investigating the use of decodeParameter method because I can see 'type' field from AbiOutput instance being passed to this function on one other occasion.

@nivida
Copy link
Contributor

nivida commented Mar 29, 2019

Thanks! I've missed that case. Will fix and release it asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants