我正在使用 Hardhat 部署智能合约,但遇到一个错误,提示“upload.deployed 不是函数”。以下是我正在使用的代码:
javascript 复制代码
// Importing the Hardhat runtime environment
const hre = require("hardhat");
async function main() {
// Fetching the contract factory for the "Upload" contract
const Upload = await hre.ethers.getContractFactory("Upload");
// Deploying the contract
const upload = await Upload.deploy();
// Awaiting the completion of the deployment
await upload.deployed();
// Output the address to which the contract was deployed
console.log("Library deployed to:", upload.address);
}
// Handling errors and setting an appropriate exit code
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
在此脚本中,我首先获取名为 Upload 的合约的合约工厂。然后,我部署此合同并等待部署完成。最后,我记录已部署合约的地址。然而,
将
await upload.deployed();
替换为 upload.waitForDeployment();
然后
将
upload.address
替换为 await upload.getAddress()
然后再次运行