Instead of receiving the contract address i'm getting undefined(HardHat, ethers.js)

385 views Asked by At
const { ethers } = require("hardhat");
const hre = require("hardhat");

async function main() {
  const currentTimestampInSeconds = Math.round(Date.now() / 1000);
  const unlockTime = currentTimestampInSeconds + 60;

  const lockedAmount = hre.ethers.parseEther("0.001");

  const lock = await hre.ethers.deployContract("Lock", [unlockTime], {
    value: lockedAmount,
  });

  const Token = await hre.ethers.getContractFactory("Token");
  const token = await Token.deploy();

  await token.deploymentTransaction().wait(1);
  console.log(`Token Deployed to: ${token.value}`);

  console.log(
    `Lock with ${ethers.formatEther(
      lockedAmount
    )}ETH and unlock timestamp ${unlockTime} deployed to ${lock.target}`
  );
}

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

output: Token Deployed to: undefined Lock with 0.001ETH and unlock timestamp 1697469516 deployed to 0x9E545E3C0baAB3E08CdfD552C960A1050f373042 Done in 3.80s.

The issue being the token's address is set to undefined not sure why, can someone help me out?

1

There are 1 answers

0
Sanju On

so the solution for this was:

change this line

  console.log(`Token Deployed to: ${token.value}`);

to:

  console.log(`Token Deployed to: ${token.target}`);

works well, i'm using ethers v6