TypeError: Cannot read property '_isHexString' of undefined
See original GitHub issueHi,
I’m using merkletreejs
for the following test:
it("return a baseURI + tokenURI for tokenId", async () => {
const [redeemer, usr1, usr2, usr3, usr4] = await ethers.getSigners()
const accounts = [redeemer.address, usr1.address, usr2.address, usr3.address, usr4.address]
const merkleTree = new MerkleTree(accounts, keccak256, {
hashLeaves: true,
sortPairs: true,
})
const root = merkleTree.getHexRoot()
const rootHashes = [root, "0x00", "0x00", "0x00", "0x00"]
const leaf = keccak256(redeemer.address)
const proof = merkleTree.getHexProof(leaf)
await makerbadges.connect(signers.deployer).setRootHashes(rootHashes)
await makerbadges.connect(signers.deployer).createTemplate(template_name, template_description, template_image)
await makerbadges.connect(redeemer).activateBadge(proof, templateId, tokenURI)
const tokenId = await makerbadges.tokenOfOwnerByIndex(redeemer.address, index1)
expect(await makerbadges.tokenURI(tokenId)).to.be.eq("https://badges.makerdao.com/token/" + tokenURI)
})
and I get the following error:
1) MakerBadges
ERC721 metadata
return a baseURI + tokenURI for tokenId:
TypeError: Cannot read property '_isHexString' of undefined
at /home/sencha/maker-badges/node_modules/merkletreejs/dist/MerkleTree.js:961:22
at Array.map (<anonymous>)
at new MerkleTree (node_modules/merkletreejs/dist/MerkleTree.js:51:29)
at Context.<anonymous> (test/MakerBadges.ts:75:26)
at step (test/MakerBadges.ts:34:23)
at Object.next (test/MakerBadges.ts:15:53)
at fulfilled (test/MakerBadges.ts:6:58)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
I’ve also tried migrating to @nomiclabs/hardhat-truffle5 and @typechain/truffle-v5, I’ve got the same issue.
OS: Ubuntu 20.04 Source Code: https://github.com/naszam/maker-badges/blob/xdai/test/MakerBadges.ts
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
TypeError: Cannot read property '_isHexString' of undefined #35
Hi, I'm using merkletreejs for the following test: it("return a baseURI + tokenURI for tokenId", async () => { const [redeemer, usr1, usr2, ......
Read more >Cannot read properties of undefined (reading 'toHexString') in ...
If you are using JavaScript and getting this error then You made a mistake while importing dotenv. you are using ".config" as property...
Read more >Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError: Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an undefined...
Read more >How to Prevent cannot read property split of ... - Gopi Gorantala
The "cannot read property split of undefined" error occurs when we try to call the split() method on a variable that stores an...
Read more >hardhat - TypeError: Cannot read properties 'toString'
The error log means that chainId is undefined. When you run the deploy script, you can specify which network config you want to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Awesome!
Hey @naszam, can you try updating to
0.2.15
or newer. The input errors you’re were seeing should be fixed.Then in your use the
sortPairs: true
option. The reason this is needed is because the solidity library is sorting them before hashing as seen here:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/243adff49ce1700e0ecb99fe522fb16cff1d1ddc/contracts/utils/cryptography/MerkleProof.sol#L27
I also noticed that
keccak256
wasundefined
so I had to import it as:To have it import regularly you need to update a setting in
tsconfig.json
And importing as expected worked:
However you can also use
soliditySha3
as the hashing function to minimize dependencies.This should definitely work now!
Test results: