下面显示了智能合约代码的示例代码
SPDX-License-Identifier: MIT
pragma solidity >=0.8.9;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract ERC20Test is ERC20Upgradeable, OwnableUpgradeable, AccessControlUpgradeable, UUPSUpgradeable {
function initialize() initializer public {
__ERC20_init("Test1", "TST1");
__Ownable_init();
__AccessControl_init();
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
function _authorizeUpgrade(address newImplementation)
internal
onlyRole(DEFAULT_ADMIN_ROLE)
override
{}
}
上述智能合约的部署脚本
require("dotenv").config();
const hre = require("hardhat");
async function main() {
try {
const provider = new hre.ethers.providers.JsonRpcProvider(
process.env.PROVIDER_URL
);
const owner = new hre.ethers.Wallet(process.env.PRIVATE_KEY, provider);
const Token = await hre.ethers.getContractFactory("Test1", owner);
const token = await hre.upgrades.deployProxy(Token, ["Test1", "TST1"], {
txOverrides: { maxFeePerGas: 10e9 },
initializer: "initialize",
owner,
});
console.log("Test Address:", token);
} catch (err) {
console.error(err);
process.exit(1);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
我们收到的错误消息
Timed out waiting for implementation contract deployment to address 0x... with transaction 0x...
当我们导航到本地 Docker 环境并检查日志时,我们发现一个合约已成功部署,而另一个合约的部署仍处于等待状态一段时间(大约 1 分钟)。在此延迟之后,将显示以下错误: