smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12.61k stars 3.01k forks source link

Lesson 5: TypeError: abi.map is not a function #3213

Open RamyTheEngineer opened 2 years ago

RamyTheEngineer commented 2 years ago
async function main() {
  //http://127.0.0.1:7545
  const provider = new ethers.providers.StaticJsonRpcProvider(
    "http://127.0.0.1:7545"
  );
  const wallet = new ethers.Wallet(
    "0e84b59ddccb5ba19af241e6ba52ba04e56ce5bf5d9a9f79b641f3c97a643388",
    provider
  );
  const abi = new fs.readFileSync(
    "./SimpleStorage_sol_SimpleStorage.abi",
    "utf8"
  );
  const binary = fs.readFileSync(
    "./SimpleStorage_sol_SimpleStorage.bin",
    "utf8"
  );
  const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
  console.log("Deploying, please wait...");
  const contract = await contractFactory.deploy();
  console.log(contract);
}

I am having this error:

TypeError: abi.map is not a function
    at new Interface (/home/ramy-unix/hh-fcc/ethers-simple-storage/node_modules/@ethersproject/abi/lib/interface.js:100:65)
    at Function.BaseContract.getInterface (/home/ramy-unix/hh-fcc/ethers-simple-storage/node_modules/@ethersproject/contracts/lib/index.js:764:16)
    at ContractFactory.getInterface (/home/ramy-unix/hh-fcc/ethers-simple-storage/node_modules/@ethersproject/contracts/lib/index.js:1192:25)
    at new ContractFactory (/home/ramy-unix/hh-fcc/ethers-simple-storage/node_modules/@ethersproject/contracts/lib/index.js:1089:116)
    at main (/home/ramy-unix/hh-fcc/ethers-simple-storage/deploy.js:21:27)
    at Object.<anonymous> (/home/ramy-unix/hh-fcc/ethers-simple-storage/deploy.js:27:1)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

Code breaks at this line

 const contractFactory = new ethers.ContractFactory(abi, binary, wallet);

timestamp: 7:08:42

alymurtazamemon commented 2 years ago

@ramykh show your abi file, see it should be inside array [{}]

Sami-Shafi commented 1 year ago

Are you sure your sol file doesn't have any problems? If you are sure it's bug-free, try deleting the binary and abi file, recompile the sol file, and then run the deploy script.