Tokens
Hardhat — 無法在 Rinkeby 上驗證 ERC20 代幣
我正在使用 Openzeppelin 的 ERC20 合約創建一個 ERC20 代幣,我使用它編寫了部署腳本
hardhat-deploy
並且它正在執行。但是,當嘗試在該智能合約的地址上執行安全帽驗證腳本時,我收到以下錯誤:NomicLabsHardhatPluginError: More than one contract was found to match the deployed bytecode. Please use the contract parameter with one of the following contracts: * @openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20 * contracts/TopGToken.sol:TopGToken For example: hardhat verify --contract contracts/Example.sol:ExampleContract <other args> If you are running the verify subtask from within Hardhat instead: await run("verify:verify", { <other args>, contract: "contracts/Example.sol:ExampleContract" };
這是我的智能合約:
// SPDX-Licence-Identifier: MIT pragma solidity ^0.8.16; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract TopGToken is ERC20 { constructor(uint256 initialSupply, string memory name, string memory symbol) ERC20 (name, symbol) { _mint(msg.sender, initialSupply); } }
這是我的部署文件:
const { network } = require('hardhat'); const { networkConfig, devChains } = require('../network.config'); const { verify } = require('../utils/verify'); module.exports = async ({ getNamedAccounts, deployments }) => { const { deploy, log } = deployments; const { deployer } = await getNamedAccounts(); const currentNetwork = networkConfig[network.config.chainId]; const isLocal = devChains.includes(currentNetwork.name); const initialSupply = currentNetwork.initialSupply; const name = "Top G Token"; const symbol = "TOPG"; const args = [ initialSupply, name, symbol, ]; const TopGToken = await deploy('TopGToken', { from: deployer, args, log: true, waitConfirmations: currentNetwork.blockConfirmations, }); if(!isLocal){ await verify(TopGToken.address, args); } log('-------------------------------------------------') } module.exports.tags = ['all', 'topgtoken'];
驗證文件:
const { run } = require('hardhat'); async function verify(contractAddress, args) { try { await run("verify:verify", { address: contractAddress, constructorArguments: args, }); } catch (error) { console.error(error) } } module.exports = { verify };
Hardhat 在項目中發現了多個合約(您的 TopGTOken 和導入的 ERC20),它不知道您要驗證哪個字節碼。
您需要指定您的契約。
async function verify(contractAddress, args) { try { await run("verify:verify", { address: contractAddress, constructorArguments: args, contract: "contracts/TopGToken.sol" }); } catch (error) { console.error(error) } }