Reputation: 11
In contracts/SimpleContract.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleContract {
string public message = "Hello, World!";
}
In scripts/deploy.js
const hre = require("hardhat");
async function main() {
console.log("Deploying SimpleContract...");
const SimpleContract = await hre.ethers.getContractFactory("SimpleContract");
const simpleContract = await SimpleContract.deploy();
console.log("Contract deployment transaction created, waiting for confirmation...");
await simpleContract.deployed();
console.log("SimpleContract deployed to:", simpleContract.address);
}
main().catch((error) => {
console.error("Error during deployment:", error);
process.exitCode = 1;
});
I try to deploy this and get this error:
C:\ProgStuff\solidity-check>npx hardhat run scripts/deploy.js --network localhost
Deploying SimpleContract...
Contract deployment transaction created, waiting for confirmation...
Error during deployment: TypeError: simpleContract.deployed is not a function
at main (C:\ProgStuff\solidity-check\scripts\deploy.js:29:24)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Why am I getting this error and how can I solve it?
Upvotes: 1
Views: 34
Reputation: 141
You have used old version of deploy script and solidity. Some functions are deprecated.
You should write as follows:
import { ethers } from 'hardhat'
async function main() {
console.log("Deploying SimpleContract...");
const [deployer] = await ethers.getSigners();
const simpleContract = await ethers.deployContract("SimpleContract");
console.log("Contract deployment transaction created, waiting for confirmation...");
await simpleContract.waitForDeployment();
const contractAddress = await simpleContract.getAddress();
console.log("SimpleContract deployed to:", contractAddress);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error("Error during deployment:", error)
process.exitCode = 1
})
Upvotes: 0