I'm trying to set up a simple token contract and deploy it but i'm having some trouble. This is the token contract
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract Token {
string public name;
string public symbol;
uint256 public decimals = 18;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
function transfer(address _to, uint256 _value) public returns (bool success) {
balanceOf[msg.sender] = balanceOf[msg.sender] - _value;
balanceOf[_to] = balanceOf[_to] + _value;
}
constructor(
string memory _name,
string memory _symbol,
uint256 _totalSupply
) {
name = _name;
symbol = _symbol;
totalSupply = _totalSupply * (10**decimals);
balanceOf[msg.sender] = totalSupply;
}
}
And this is the deployment script:
async function main() {
//Fetch contract to deploy
const Token = await ethers.getContractFactory("Token");
//Deploy contract
const token = await Token.deploy("Token", "MTK", 1000000);
await token.deployed();
console.log(`Token deployed to: ${token.address}`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
The contract deploys okay and gives me this output:
Token deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
However when i try to run the the following command i get an error:
const token = await ethers.getContractAt("Token", "0x5FbDB2315678afecb367f032d93F642f64180aa3")
Uncaught:
NomicLabsHardhatPluginError: 0x5FbDB2315678afecb367f032d93F642f64180aa3 is not a contract
account.
at REPL12:1:41
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at getContractAt (....\node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:307:11)
I don't understand what i'm doing wrong.