question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read properties of undefined (reading 'toHexString')

See original GitHub issue

Ethers Version

^5.0.0

Search Terms

No response

Describe the Problem

I am trying to execute a transaction and I get

TypeError: Cannot read properties of undefined (reading 'toHexString')
    at isHexable (/node_modules/@ethersproject/bytes/src.ts/index.ts:58:21)
    at arrayify (/node_modules/@ethersproject/bytes/src.ts/index.ts:115:9)
    at FixedBytesCoder.encode (/node_modules/@ethersproject/abi/src.ts/coders/fixed-bytes.ts:22:28)
    at /node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19
    at Array.forEach (<anonymous>)
    at pack (//node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)
    at TupleCoder.encode (/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20)
    at /node_modules/@ethersproject/abi/src.ts/coders/array.ts:62:19
    at Array.forEach (<anonymous>)
    at pack (/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)

Code Snippet

https://github.com/Dimo99/light-client-smart-contract

in this repo run `npx hardhat deploy`

The json file I am loading is this one `https://github.com/metacraft-labs/eth2-light-client-updates/blob/main/mainnet/updates/00290.json`

Contract ABI

No response

Errors

TypeError: Cannot read properties of undefined (reading 'toHexString')
    at isHexable (/node_modules/@ethersproject/bytes/src.ts/index.ts:58:21)
    at arrayify (/node_modules/@ethersproject/bytes/src.ts/index.ts:115:9)
    at FixedBytesCoder.encode (/node_modules/@ethersproject/abi/src.ts/coders/fixed-bytes.ts:22:28)
    at /node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19
    at Array.forEach (<anonymous>)
    at pack (//node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)
    at TupleCoder.encode (/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20)
    at /node_modules/@ethersproject/abi/src.ts/coders/array.ts:62:19
    at Array.forEach (<anonymous>)
    at pack (/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)

Environment

Hardhat

Environment (Other)

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ricmoocommented, Aug 9, 2022

@Dimo99 Thats directly from the JavaScript language and runtime. There isn’t much I can do about that… it has nothing to do with ethers. If you have an undefined value (in any variable) and attempt to access a property on it, JS (correctly) complains. 😃

0reactions
Dimo99commented, Aug 9, 2022

@ricmoo actually fork_version was part of my structure. This is the most minimalistic example.

contract Example {
    struct FinalizedHeaderUpdate {
        bytes4 fork_version;
    }

    function light_client_update(FinalizedHeaderUpdate calldata update) external {
        require(2 > 1, "Test");
    }
}
    const result = await exampleContract.light_client_update({asd: "asd"}); // fails with Cannot read properties of undefined (reading 'toHexString')

    const result1 = await exampleContract.light_client_update({fork_version: "0x00000000"}); // works properly

I know the first statement is expected to fail. But I guess Cannot read properties of undefined (reading 'toHexString') is not a nice message

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'toHexString') in ...
Another problem you might have is where your .env is located. Make sure that your .env is in the same folder as your...
Read more >
Cannot read properties of undefined (reading 'toHexString')
Hey Devs I want to interact with this smart contract function but i get this error Cannot read properties of undefined (reading ......
Read more >
"Cannot read property 'toHexString' of undefined". Try ... - Reddit
bought a new token from uniswap, but cant swap back eth and shows Unknown error: "Cannot read property 'toHexString' of undefined". Try ...
Read more >
Getting 'TypeError: Cannot read properties of undefined ...
The error is thrown in the method signMessage from the EthersAdapter class: signMessage(message: string): Promise<string> { const ...
Read more >
Running Error : Type Error in index.js - Alchemy Docs
... the error is : TypeError: Cannot read properties of undefined (reading 'toHexString') How can I solve this problem , Please help.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found