I got an error which I don't understand, and that I don't remember defining anywhere in the code, can someone explain what the issue is? Thanks a lot.
properties_1.defineReadOnly(this, "fragments", abi.map(function (fragment) {
^
TypeError: Cannot read property 'map' of undefined
This is my code:
const { ethers } = require("hardhat");
const {abi} = require('./build/abi/mycontract.json');
require('dotenv').config();
const { ALCHEMY_API_KEY, ACCOUNT2_PRIVATE_KEY, ACCOUNT2_PUBLIC_KEY,CONTRACT_ADDRESS} = process.env;
const provider = ethers.getDefaultProvider('rinkeby', {
alchemykey: ALCHEMY_API_KEY
});
const wallet = new ethers.Wallet.createRandom();
const walletWithProvider = wallet.connect(provider);
const mycontract = new ethers.Contract(CONTRACT_ADDRESS,abi,walletWithProvider);
async function stakeliquidity(){
await contractW.stakeCombinedLiquidity()
.then(() => {
console.log('staked succesfully');
}).catch(() => console.log('transaction error'));
console.log('function called.');
}
stakeliquidity();
//Unstake
Best Answer
TLDR; The
abi
declared in your Line 2 (const {abi} = ..
) could be undefined. You can verify it bby console logging.You get the
Cannot read property '*' of undefined
error when somewhere in your code if you're using a library, you're passing an undefined value by mistake. Also, this saysproperty 'map'
, which means that the library function expects the value as an Array. Luckily, you also have a code snippet that triggered this error and it containsabi.map
, and the variable name suggests it'sabi
, though this is from ethers.js codebase not yours.