0

I've created one contract and trying to deploy it locally to test it. But it's not deploying. It throws this error, enter image description here

This is the code in scripts/deploy.js file,


async function main() {
  const tracking = await hre.ethers.deployContract("Tracking");

  await tracking.waitForDeployment();

  console.log(`Tracking deployed to ${tracking.target}`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

My contract name and filename is Tracking and Tracking.sol

This is the hardhat and ethers versions I'm using,

    "hardhat": "^2.17.4",

Since I'm new to blockchain development I don't know why this error is coming, any help on this would be appreciated.

1

1 Answer 1

0

you can do following step for remove error

step 1: delete node module folder step 2: change ether version in package.json to ^6.7.1 step 3: run below code in cmd

npm install 

step 4: after run your js script there is no error in js script after that if error come then its problem

check where is ether_1.getAddress function because in your cmd error says this is not a function

try this example

Greeter.sol

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "hardhat/console.sol";

contract Greeter{
    string private greeting;

    constructor(){
        greeting="hello,world";
    }

    function greet() public view returns(string memory){
        return greeting;
    }

    function setGreeting(string memory _greeting) public {
        console.log("The greeting will be changed from %s to %s",greeting,_greeting);
        greeting=_greeting;
    }
}

deploy.js

async function main() {
  const greeter = await hre.ethers.deployContract("Greeter");
  await greeter.waitForDeployment();
  console.log(`contract deployed to ${greeter.target}`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

deploy this example because its work in my system

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.