Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract deployed at undefined #6711

Open
MustafaMansoor opened this issue Aug 10, 2024 Discussed in #6710 · 1 comment
Open

Contract deployed at undefined #6711

MustafaMansoor opened this issue Aug 10, 2024 Discussed in #6710 · 1 comment

Comments

@MustafaMansoor
Copy link

Discussed in #6710

Originally posted by MustafaMansoor August 10, 2024
Hi,
In the tutorial, the deployment was done on Rinkeby, but since it was deprecated, I decided to deploy on the Sepolia testnet. I added my API key from MetaMask and selected the Sepolia network in Alchemy. However, I'm encountering an issue where the contract address shows as undefined after deployment. The transaction amount is being deducted from my MetaMask, so I believe the contract is being deployed, but I can't figure out what's causing the issue. Any help would be appreciated.

here is the code

const ethers = require("ethers");
const fs = require("fs-extra");
require("dotenv").config();

const main = async () => {
  const provider = new ethers.JsonRpcProvider(process.env.URL);

  const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

  const abi = fs.readFileSync("./simpleStorage_sol_SimpleStorage.abi", "utf8");
  const binary = fs.readFileSync(
    "./simpleStorage_sol_SimpleStorage.bin",
    "utf8"
  );

  const contractFac = new ethers.ContractFactory(abi, binary, wallet);
  console.log("Deploying contract, please wait...");

  const contract = await contractFac.deploy();

  // Wait for the contract deployment to be mined
  await contract.waitForDeployment("1");

  // Now the address should be available
  console.log(`Contract deployed at ${contract.address}`);

  // Retrieve the initial value stored in the contract
  // const res = await contract.retrieve();
  // console.log("Initial retrieved value:", res.toString());

  // // Store a new value
  // const TransRes = await contract.store("1217");
  // await TransRes.wait(); // Wait for 1 confirmation
  // console.log("New value stored.");

  // // Retrieve the updated value
  // const update = await contract.retrieve();
  // console.log("Updated retrieved value:", update.toString());
};

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

and here is the error

Deploying contract, please wait...
Contract deployed at undefined
@ishagarg1809
Copy link

ishagarg1809 commented Aug 18, 2024

I think the contract object has been changed recently, you can find the contract address at target.
Update your code from

  console.log(`Contract deployed at ${contract.address}`);

to

console.log(`Contract deployed at ${contract.target}`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants