interact.ts 808 B

123456789101112131415161718192021222324
  1. import { ethers } from "hardhat";
  2. async function main() {
  3. const [signer] = await ethers.getSigners();
  4. const contractAddress = "0x389CF3447C2867f767303d670193ee54343B20d7"; // Replace with your deployed contract address
  5. const MyToken = await ethers.getContractFactory("MyRewardToken");
  6. const myToken = MyToken.attach(contractAddress);
  7. // Check balance of the signer
  8. const balance = await myToken.balanceOf(signer.getAddress());
  9. console.log(`Balance of`, signer.getAddress(), ethers.formatEther(balance));
  10. // Mint new tokens (if you're the owner)
  11. const mintTx = await myToken.mint(signer.address, ethers.parseEther("100"));
  12. await mintTx.wait();
  13. console.log("Minted 100 tokens to", signer.getAddress());
  14. }
  15. main().catch((error) => {
  16. console.error(error);
  17. process.exitCode = 1;
  18. });