Solidity

嘗試執行契約但總是遇到同樣的錯誤

  • July 19, 2022
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9; 
import "opezeppilines/openzeppelin-contracts-master/contracts/token/ERC20/ERC20.sol";

contract currency is ERC20 {
   constructor(string memory name,string memory symbol) ERC20(name,symbol)
   {
       _mint(msg.sender,10*10**18);
       
   }
}

我的貨幣.sol

async function main()
{
   const {deployer} = await ethers.getSigners();
   const Token = await ethers.getContractFactory("currency");
   const token = await Token.deploy();
}

main().then(() => process.exit(0))
.catch(
err => {console.error(err);
process.exit(1);
});

我的 deploy.js

PS E:\vs code files> npx hardhat run --network Goerli scripts/deploy.js
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
× Help us improve Hardhat with anonymous crash reports & basic usage data? (Y/n) · y
Error: missing argument:  in Contract constructor (count=0, expectedCount=2, code=MISSING_ARGUMENT, version=contracts/5.6.2)
   at Logger.makeError (E:\vs code files\node_modules\@ethersproject\logger\src.ts\index.ts:261:28)
   at Logger.throwError (E:\vs code files\node_modules\@ethersproject\logger\src.ts\index.ts:273:20)
   at Logger.checkArgumentCount (E:\vs code files\node_modules\@ethersproject\logger\src.ts\index.ts:332:18)
   at ContractFactory.<anonymous> (E:\vs code files\node_modules\@ethersproject\contracts\src.ts\index.ts:1237:16)
   at step (E:\vs code files\node_modules\@ethersproject\contracts\lib\index.js:48:23)
   at Object.next (E:\vs code files\node_modules\@ethersproject\contracts\lib\index.js:29:53)
   at E:\vs code files\node_modules\@ethersproject\contracts\lib\index.js:23:71
   at new Promise (<anonymous>)
   at __awaiter (E:\vs code files\node_modules\@ethersproject\contracts\lib\index.js:19:12)
   at ContractFactory.deploy (E:\vs code files\node_modules\@ethersproject\contracts\lib\index.js:1138:16) {
 reason: 'missing argument:  in Contract constructor',
 code: 'MISSING_ARGUMENT',
 count: 0,
 expectedCount: 2
}

錯誤資訊

您的建構子需要 2 個值作為輸入,而您沒有在腳本中提供這些值。namesymbol。_ 將您的程式碼行更改為以下內容:

const token = await Token.deploy("tokenName", "tokenSymbol");

您共享的第一個契約程式碼中還有一個錯字。你寫opezeppilines的,但應該是openzeppelin

在這裡更正:

//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9; 
import "openzeppelin/openzeppelin-contracts-master/contracts/token/ERC20/ERC20.sol";

contract currency is ERC20 {
   constructor(string memory name,string memory symbol) ERC20(name,symbol)
   {
       _mint(msg.sender,10*10**18);
       
   }
}

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