Solidity

HardhatError:HH700:未找到合約的工件

  • August 19, 2022

我的程式碼不斷出現這個錯誤,我參考了另一篇關於“Greeter.sol”類似問題的文章,但這似乎不是我的問題。

這是我的 .sol 文件程式碼:

//SPDX-License-Identifier: MIT pragma solidity ^0.8.4;

導入“@openzeppelin/contracts/token/ERC20/ERC20.sol”;導入“@openzeppelin/contracts/access/Ownable.sol”;

合約 Btc 是 ERC20, Ownable { constructor() ERC20(“Dogecoin”, “DOGE”){}

function mint(address to, uint256 amount) public payable{
   _mint(to, amount);
}

receive() external payable{}

}

以下是我不斷收到的錯誤:

HardhatError:HH700:未找到合約“Dogecoin”的工件。在 Artifacts._handleWrongArtifactForContractName (/home/muskaan/moti-milo/smart-contract/node_modules/hardhat/src/internal/artifacts.ts:478:11) 在 Artifacts._getArtifactPathFromFiles (/home/muskaan/moti-milo/smart- contract/node_modules/hardhat/src/internal/artifacts.ts:593:19) 在 Artifacts._getArtifactPath (/home/muskaan/moti-milo/smart-contract/node_modules/hardhat/src/internal/artifacts.ts:275: 17) 在 Artifacts.readArtifact (/home/muskaan/moti-milo/smart-contract/node_modules/hardhat/src/internal/artifacts.ts:58:26) 在 getContractFactory (/home/muskaan/moti-milo/smart- contract/node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:99:22)在主要(/home/muskaan/moti-milo/smart-contract/scripts/deploy.js:4:25)在/home/muskaan/moti-milo/smart-contract/scripts/deploy.

請幫忙,我已經卡了一段時間了。

這是我的 deploy.js 文件:

const { ethers } = require(‘hardhat’)

const main = async() => { const dogeFactory = await ethers.getContractFactory(‘Dogecoin’) const dogeContract = await dogeFactory.deploy() await dogeContract.deployed() console.log(‘Dogecoin 部署到:’, dogeContract.address )

const bitcoinFactory = await ethers.getContractFactory('Btc')
const bitcoinContract = await bitcoinFactory.deploy()
await bitcoinContract.deployed()
console.log('Bitcoin deployed to:', bitcoinContract.address)


const solanaFactory = await ethers.getContractFactory('Solana')
const solanaContract = await solanaFactory.deploy()
await solanaContract.deployed()
console.log('Solana deployed to:', solanaContract.address)


const usdcFactory = await ethers.getContractFactory('Usdc')
const usdcContract = await usdcFactory.deploy()
await usdcContract.deployed()
console.log('USDC deployed to:', usdcContract.address)

}

;(async ()=>{ try{ await main() process.exit(0) } catch(error){ console.error(error) process.exit(1) } })()

我使用’$ npx hardhat run scripts/deploy.js –network rinkeby’進行部署

由於您將合約命名為“Btc”,因此您的 getContractFactory 上的名稱也應該同步。

在您的 Dogecoin.sol 上不要使用:

contract Btc is ERC20, Ownable { ...

改為使用:

contract Dogecoin is ERC20, Ownable { ...

然後,不要更改您的 deploy.js。然後執行:

npx hardhat clean
npx hardhat deploy scripts/deploy.js --network rinkeby

它應該工作得很好。

引用自:https://ethereum.stackexchange.com/questions/133907