Solidity
在嘗試通過 HardHat 功能編譯我的契約時,我不斷收到此錯誤
這是我的腳本
deploy.js
:const main = async () => { // We get the contract to deploy const Transactions = await hre.ethers.getContractFactory("Transactions"); const transactions = await Transactions.deploy(""); await greeter.deployed(); console.log("Greeter deployed to:", greeter.address); } const runMain = async() => { try { await main(); Process.exit(0); } catch (error) { console.error(error); process.exit(1); } } runMain();
這是我的腳本
hardhat.config.js
:// This is a sample Hardhat task. // https://eth-ropsten.alchemyapi.io/v2/Bn5tm9fX90ET1hKwb76lKJB0rzU3JBi2 require("@nomiclabs/hardhat-waffle"); module.exports = { solidity: '0.8.0', networks: { ropsten: { url: "https://eth-ropsten.alchemyapi.io/v2/Bn5tm9fX90ET1hKwb76lKJB0rzU3JBi2", accounts: ["63b598044c3cce8d656............b7c64beb17eb1687aebbefc5cac8a"] } } }
這是我的solidity合約腳本:
// SPDX-License-Identifier: MIT pragma experimental ABIEncoderV2; pragma solidity >=0.6.0 <0.9.0; contract Transactions { uint256 transactionCount; event Transfer( address from, address reciever, uint256 amount, string message, uint256 timestamp, string keyword ); struct TransferStruct { address sender; address reciever; uint256 amount; string message; uint256 timestamp; string keyword; } TransferStruct[] transactions; function addToBlockchain( address payable reciever, uint256 amount, string memory message, string memory keyword ) public { transactionCount += 1; transactions.push( TransferStruct( msg.sender, reciever, amount, message, block.timestamp, keyword ) ); emit Transfer( msg.sender, reciever, amount, message, block.timestamp, keyword ); } function getAllTransactions() public view returns (TransferStruct[] memory) { return transactions; } function getTransactionCount() public view returns (uint256) { return transactionCount; } }
以下是我在嘗試編譯時收到的錯誤消息:
PS C:\Users\Temitope\Desktop\kredar\smart_contract> npx hardhat run scripts/deploy.js --network ropsten Error: too many arguments: in Contract constructor (count=1, expectedCount=0, code=UNEXPECTED_ARGUMENT, version=contracts/5.6.0) at Logger.makeError (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\logger\src.ts\index.ts:261:28) at Logger.throwError (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\logger\src.ts\index.ts:273:20) at Logger.checkArgumentCount (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\logger\src.ts\index.ts:339:18) at ContractFactory.getDeployTransaction (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\contracts\src.ts\index.ts:1218:16) at ContractFactory.<anonymous> (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\contracts\src.ts\index.ts:1246:53) at step (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\contracts\lib\index.js:48:23) at ContractFactory.<anonymous> (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\contracts\src.ts\index.ts:1246:53) at step (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\contracts\lib\index.js:48:23) at Object.next (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\contracts\lib\index.js:29:53) at fulfilled (C:\Users\Temitope\Desktop\kredar\smart_contract\node_modules\@ethersproject\contracts\lib\index.js:20:58) at processTicksAndRejections (node:internal/process/task_queues:96:5) { reason: 'too many arguments: in Contract constructor', code: 'UNEXPECTED_ARGUMENT', count: 1, expectedCount: 0 }
請讓我知道我做錯了什麼以及如何解決它。
錯誤消息清楚地表明您的合約不期望作為建構子的參數。
試試
const transactions = await Transactions.deploy();
你的程式碼。
實施後這是我得到的錯誤
PS C:\Users\Temitope\Desktop\kredar\smart_contract> npx hardhat run scripts/deploy.js –network ropsten ReferenceError: greeter is not defined at main (C:\Users\Temitope\Desktop\kredar\smart_contract\scripts\ deploy.js:8:3) at processTicksAndRejections (node:internal/process/task_queues:96:5) at runMain (C:\Users\Temitope\Desktop\kredar\smart_contract\scripts\deploy.js:15:5) PS C:\Users\Temitope\Desktop\kredar\smart_contract>