skip to Main Content

**I want to deploy a smart contract and wait for the deployment transaction of the contract to be mined but i am running into some error **
**version used **

 "dotenv": "^16.3.1",
 "ethers": "^6.6.4",
 "fs-extra": "^11.1.1",
 "solc": "^0.8.7-fixed"

code:

const { ethers, JsonRpcProvider } = require("ethers");
const fs = require("fs-extra");
require("dotenv").config();

async function main() {
  const provider = new JsonRpcProvider(process.env.RPC_URL);
  const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); 
  const abi = fs.readFileSync("./simple_storage_sol_SimpleStroge.abi", "utf8");
  const bytecode = fs.readFileSync("./simple_storage_sol_SimpleStroge.bin", "utf8");

  const contractFactory = new ethers.ContractFactory(abi, bytecode, wallet);
  console.log("Deploying......");
  const contract = await contractFactory.deploy();
  await contract.deployTransaction.wait(1); 
  console.log(`Contract address: ${contract.address}`);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

i have used await contract.deployed(); suggested by chatgpt
but it’s giving the similar error

error

Deploying......
TypeError: no matching function (argument="key", value="deployTransaction", code=INVALID_ARGUMENT, version=6.6.4)
    at makeError (/home/amitx13/code_fcc/ether_simple_storage/node_modules/ethers/lib.commonjs/utils/errors.js:118:21)
    at assert (/home/amitx13/code_fcc/ether_simple_storage/node_modules/ethers/lib.commonjs/utils/errors.js:142:15)
    at assertArgument (/home/amitx13/code_fcc/ether_simple_storage/node_modules/ethers/lib.commonjs/utils/errors.js:154:5)
    at Interface.getFunctionName (/home/amitx13/code_fcc/ether_simple_storage/node_modules/ethers/lib.commonjs/abi/interface.js:433:39)
    at buildWrappedMethod (/home/amitx13/code_fcc/ether_simple_storage/node_modules/ethers/lib.commonjs/contract/contract.js:240:34)
    at BaseContract.getFunction (/home/amitx13/code_fcc/ether_simple_storage/node_modules/ethers/lib.commonjs/contract/contract.js:701:22)
    at Object.get (/home/amitx13/code_fcc/ether_simple_storage/node_modules/ethers/lib.commonjs/contract/contract.js:604:39)
    at main (/home/amitx13/code_fcc/ether_simple_storage/deploy.js:29:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'INVALID_ARGUMENT',
  argument: 'key',
  value: 'deployTransaction'
}

2

Answers


  1. Chosen as BEST ANSWER

    oo its actually a version problem use V5.7 npm i [email protected] after installing V5.7 you also need to import the JsonRpcProvider i.e new ethers.providers.JsonRpcProvider(process.env.RPC_URL); instead of importing in the constructor


  2. The problem is related to BaseContract class changes in the ethers-v6. To get the deployed instance you should use waitForTheDeployment() instead of deploy().
    Link

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search