智能合约部署需要很长时间



我使用Alchemy作为Web3提供商来部署我的Hardhat智能合约。它在部署了合同的工厂之后部署合同时停止。(Ropsten Testnet(

const hre = require("hardhat"); //import the hardhat
async function main() {
console.log("[4] Getting Deployer")
const [deployer] = await ethers.getSigners(); //get the account to deploy the contract
console.log("[+] Deploying contracts with the account:", deployer.address);
console.log("[3] Getting Factory")
const Factory = await hre.ethers.getContractFactory(
"BlockchainNamingService"
); // Getting the Contract
console.log("[2] Getting Smart Contract")
const smartContract = await Factory.deploy(); //deploying the contract
console.log("[1] Deploying Smart Contract")
await smartContract.deployed(); // waiting for the contract to be deployed
console.log("[FINISHED] Contract deployed to:", smartContract.address); // Returning the contract address on the rinkeby
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
}); // Calling the function to deploy the contract
npx hardhat run scripts/deploy.js --network ropsten

网络、我的合同或部署脚本有问题吗?

部署事务很可能由于煤气费低而被卡住。

您可以在安全帽配置中将gasPrice设置为足够的值

networks: {
goerli: {
url: API_URL,
accounts: [PRIVATE_KEY],
gasPrice: 30000000000, // this is 30 Gwei
},
},

当事务被卡住时,还会发生的情况是,在解决卡住的事务之前,不会确认新的事务。在这种情况下,可以通过发送具有相同随机数的新事务来覆盖挂起的事务。您可以在炼金术仪表板mempool选项卡中看到挂起的事务及其nonce。

nonce可以在deploy函数中设置:

await Factory.deploy({nonce: 5})

最新更新