在铸造 NFT 时,我们正在使用 MerkleTreeJS 来节省我们的社区 Gas 费。但是,当我们将证明发送到合约时,我们会收到以下错误:
index.js:238 Uncaught (in promise) TypeError: t.substring is not a function
at c.formatParam (index.js:238:23)
at index.js:217:36
at Array.map (<anonymous>)
at c.formatParam (index.js:217:22)
at index.js:99:22
at Array.map (<anonymous>)
at c.encodeParameters (index.js:93:21)
at index.js:462:20
at Array.map (<anonymous>)
at Object.y._encodeMethodABI (index.js:461:8)
您知道我们如何正确解析数组吗?
这是我们的代码:
const leaves = [
"0x9811e43A71C85CC5f9BdA9822A7459d43A932dd9",
"0x0b371Cf8550923F67e90e5Bb26371e7A7b085b27",
"0xdc0cf0dFF9569209ba0F433e34743A8027A3c9E8",
"0xc4702bfea6410c082f3908fa270b3730fbc33e38"
].map(x => SHA256(x));
const tree = new MerkleTree(leaves, SHA256);
const root = tree.getRoot().toString('hex');
const leaf = SHA256(localStorage.userWallet);
proof = tree.getProof(leaf);
if (tree.verify(proof, leaf, root) === true) {
// address whitelisted
} else {
// not on whitelist
}