Reputation: 1
Here is the code for the contract:
//contracts/TestToken.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
contract TestToken is ERC20Capped {
address payable public owner;
constructor(uint256 cap) ERC20("TestToken", "TST") ERC20Capped(cap * (10 ** decimals()))
{
owner = payable(msg.sender);
_mint(owner, 333666999000 * (10 ** decimals()));
}
function _mint(address account, uint256 amount) internal virtual override {
require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
super._mint(account, amount);
}
function destroy() public onlyOwner {
selfdestruct(owner);
}
modifier onlyOwner {
require(msg.sender == owner, "Only the owner can call this function");
_;
}
}`
Here is the deploy.js that gives the error:
const hre = require("hardhat");
async function main() {
const TestToken = await hre.ethers.getContractFactory("TestToken");
const testToken = await TestToken.deploy(333666999000);
await testToken.deployed();
console.log("Test Token deployed: ", testToken.address);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Terminal error: TypeError: testToken.deployed is not a function at main (C:\Users\XXXX\OneDrive\Desktop\ERC 20\test-token\scripts\deploy.js:7:19) at processTicksAndRejections (node:internal/process/task_queues:95:5)
Hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.17",
networks: {
goerli: {
url: process.env.INFURA_GOERLI_ENDPOINT,
accounts: [process.env.PRIVATE_KEY]
}
}
};
And here is the error:(https://i.sstatic.net/pO9x6.png)
Sorry guys, might be a silly contract, tried for myself for 3 days now, have little to no experience on Solidity, I'm just trying to learn! Thank you!
(My no-skill guess was that I was missing a package but I searched the whole internet and found only a package about it, the hardhat-ethers one and still, didn't work)
Hardhat Version: 2.17.2
Upvotes: 0
Views: 178
Reputation: 858
Seems like there was a major update to hardhat, try replacing deployed with waitForDeployment()
Upvotes: 0