0
const hre = require("hardhat");

// Returns the ether balance of a given address.
async function getBalance(address) {
  const balanceBigInt = await hre.ethers.provider.getBalance(address);
  return hre.ethers.utils.formatEther(balanceBigInt);
}

// Logs the Ether balances for a list of addresses.
async function printBalances(addresses) {
  let index = 0;
  for (const address of addresses) {
    console.log(`Addresses ${index} balance: `, await getBalance(address));
    index++;
  }
}

// Logs the memos stored on-chain from coffee purchases.
async function printMemos(memos) {
  for (const memo of memos) {
    const timestamp = memo.timestamp;
    const tipper = memo.name;
    const tipperAddress = memo.from;
    const message = memo.message;
    console.log(`At ${timestamp}, ${tipper} (${tipperAddress}) said: "${message}"`);
  }
}
console.log("2");
async function main() {
  // Get the example accounts we'll be working with.
  const [owner, tipper, tipper2, tipper3] = await hre.ethers.getSigners();
  console.log("3");
  const BuyMeACoffee = await hre.ethers.getContractFactory('BuyMeACoffee');
  const buyMeACoffee = await BuyMeACoffee.deploy();
  console.log("4");
  // Deploy the contract.
  await buyMeACoffee.deployed();
  console.log("6");
  console.log("BuyMeACoffee deployed to:", buyMeACoffee.address);
  console.log("5");
  // Check balances before the coffee purchase.
  const addresses = [owner.address, tipper.address, buyMeACoffee.address];
  console.log("== start ==");
  await printBalances(addresses);

  // Buy the owner a few coffees.
  const tip = { value: hre.ethers.utils.parseEther("1") };
  await buyMeACoffee.connect(tipper).buyCoffee("Rahul", "You're a good coder", tip);
  await buyMeACoffee.connect(tipper2).buyCoffee("Suprit", "You're a good coder", tip);
  await buyMeACoffee.connect(tipper3).buyCoffee("Prasad", "You're a good coder", tip);

  // Check balances after the coffee purchase.
  console.log("== bought coffee ==");
  await printBalances(addresses);

  // Withdraw.
  await buyMeACoffee.connect(owner).withdrawTips();

  // Check balances after withdrawal.
  //console.log("== withdrawTips ==");
  await printBalances(addresses);

  // Check out the memos.
  console.log("== memos ==");
  const memos = await buyMeACoffee.getMemos();
  printMemos(memos);

}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

TypeError: no matching function (argument="key", value="deployed", code=INVALID_ARGUMENT, version=6.6.3) at makeError ) { code: 'INVALID_ARGUMENT', argument: 'key', value: 'deployed' }

1
  • "devDependencies": { "@nomicfoundation/hardhat-toolbox": "^3.0.0", "hardhat": "^2.17.0" }
    – Indul
    Commented Aug 8, 2023 at 11:21

2 Answers 2

2

This is due to the changes in hardhat-tools 3.0.0. Make the following changes

  • deploy => deployContract - directly pass the contract name and not the factory.
  • deployed => waitForDeployment

Your main function would look like:

    async function main() {
  // Get the example accounts we'll be working with.
  const [owner, tipper, tipper2, tipper3] = await hre.ethers.getSigners();
  console.log("3");
  const BuyMeACoffee = await 
  const buyMeACoffee = await ethers.deployContract("BuyMeACoffee");
  console.log("4");
  // Deploy the contract.
  await buyMeACoffee.waitForDeployment();
  console.log("6");
  console.log("BuyMeACoffee deployed to:", buyMeACoffee.address);
  console.log("5");
  // Check balances before the coffee purchase.
  const addresses = [owner.address, tipper.address, buyMeACoffee.address];
  console.log("== start ==");
  await printBalances(addresses);

  // Buy the owner a few coffees.
  const tip = { value: hre.ethers.utils.parseEther("1") };
  await buyMeACoffee.connect(tipper).buyCoffee("Rahul", "You're a good coder", tip);
  await buyMeACoffee.connect(tipper2).buyCoffee("Suprit", "You're a good coder", tip);
  await buyMeACoffee.connect(tipper3).buyCoffee("Prasad", "You're a good coder", tip);

  // Check balances after the coffee purchase.
  console.log("== bought coffee ==");
  await printBalances(addresses);

  // Withdraw.
  await buyMeACoffee.connect(owner).withdrawTips();

  // Check balances after withdrawal.
  //console.log("== withdrawTips ==");
  await printBalances(addresses);

  // Check out the memos.
  console.log("== memos ==");
  const memos = await buyMeACoffee.getMemos();
  printMemos(memos);

}
7
  • showing the same error.
    – Indul
    Commented Aug 9, 2023 at 16:36
  • Check the ethers version and update or downgrade accordingly.
    – DevCrypto
    Commented Aug 10, 2023 at 6:21
  • using the latest version of ethers but still not working.
    – Indul
    Commented Aug 10, 2023 at 7:00
  • How can it be the same error when you're not using deployed word any more? Commented Aug 10, 2023 at 9:19
  • yeah, that issue is solved but now it's showing -> TypeError: Cannot read properties of undefined (reading 'formatEther')
    – Indul
    Commented Aug 10, 2023 at 9:43
0

Replace .deployed() with .waitForDeployment() - These updates result from hardhat-tools 3.0.0 changes.

1
  • still showing the same error.
    – Indul
    Commented Aug 9, 2023 at 16:36

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.