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

"coder.coders undefined" (Cannot read property 'forEach' of undefined) #3538

Closed
pepoospina opened this issue May 23, 2020 · 6 comments · Fixed by #3541
Closed

"coder.coders undefined" (Cannot read property 'forEach' of undefined) #3538

pepoospina opened this issue May 23, 2020 · 6 comments · Fixed by #3541
Labels
1.x 1.0 related issues Bug Addressing a bug

Comments

@pepoospina
Copy link

Expected behavior

Properties of internal objects of the library should not be undefined.

Actual behavior

The coders property of the coder variable is undefined

Steps to reproduce the behavior

I can't create a simple repo to reproduce it. I can only tell you that the only thing I changed on my codebase was the version of web3.js. From 1.2.1 to 1.2.8

Logs

I am trying to send a transaction of which some of its parameters are an of type tuple[]. This line of
code from web3.js/packages/web3-eth-abi/src/index.js

     coder.coders.forEach((c, i) => {

fails with an error.

index.js:187 Uncaught (in promise) TypeError: Cannot read property 'forEach' of undefined

If I debug the error I see that the variable coder is

> coder
ArrayCoder {name: "array", type: "tuple()[]", localName: null, dynamic: true, coder: TupleCoder, …}
coder: TupleCoder
    coders: []
    dynamic: false
    localName: null
    name: "tuple"
    type: "tuple()"
    __proto__: Coder
dynamic: true
length: -1
localName: null
name: "array"
type: "tuple()[]"

So coder.coders is undefined but coder.coder.coders is [];

By the way, the param variable is

param
[{…}]
0:
context: "genesis-dao-wiki-7930_1590231082784"
perspective:
    headCid0: "0xbe9beb848cc43c9dec36499c8a8f2ef73de9ace310592b38f928e50dd0e25869"
    headCid1: "0x0000000000000000000000000000000000000000000000000000007a01551220"
    owner: "0xffcf8fdee72ac11b5c542428b35eef5769c409f0"
    perspectiveId: "zb2rhckLbBQCH9wUWvD4K2itS1wTMC1wRRfVCUEacUhkDutCv"

Environment

works fine with

    "web3": "^1.2.1",
    "web3-eth-contract": "^1.2.1",
    "web3-utils": "^1.2.1"

fails with

    "web3": "^1.2.8",
    "web3-eth-contract": "^1.2.8",
    "web3-utils": "^1.2.8"

I am using "webpack": "^4.10.2", to build the frontend app.

@pepoospina pepoospina changed the title "coder.coders undefined" (connot find forEach of undefined) "coder.coders undefined" (Cannot read property 'forEach' of undefined) May 23, 2020
@cgewecke
Copy link
Collaborator

@pepoospina

Can you share the function signature of the Solidity method you're calling and any relevant data type definitions so we can reproduce and fix?

@malaak-habashy
Copy link

malaak-habashy commented May 25, 2020

I encountered the same issue

online example of the issue and the code I wrote. in the link below:
https://malaak-habashy.github.io/

I also asked about this issue on stackoverflow
https://stackoverflow.com/questions/61973747/how-to-send-an-array-of-structs-from-web3js-to-solidity-contract

@ryanio
Copy link
Collaborator

ryanio commented May 25, 2020

Hey guys, thanks for reporting, I was able to recreate the issue by adding a test for an array of tuples to test/abi.encodeParameter.js e.g.:

test({
  types: ['tuple(string,uint)[]'],
  values: [[['item1', 2], ['item2', 3]]],
  ...
});

I will work on a PR to fix this. edit: see #3541

@ryanio ryanio added 1.x 1.0 related issues Bug Addressing a bug labels May 25, 2020
@malaak-habashy
Copy link

@ryanio thank you

@ryanio ryanio mentioned this issue Jun 2, 2020
13 tasks
@layinka
Copy link

layinka commented Feb 2, 2022

Getting this error on web3 1.7.0

@nyunyunyunyu
Copy link

nyunyunyunyu commented Feb 6, 2022

Getting this error on web3 1.7.0

+1 Sry my bad. It's totally unrelated.

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

Successfully merging a pull request may close this issue.

6 participants