Problem:
While deploying the contract using hardhat ignition I am facing this strange error. I have provided the smart contract and the deploy script below. I am deploying on sepolia testNet.
This is my Voting Smart Contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Voting {
struct Candidate {
string name;
uint256 voteCount;
}
Candidate[] public candidates;
address owner;
mapping(address => bool) public voters;
uint256 public votingStart;
uint256 public votingEnd;
constructor(string[] memory _candidateName, uint256 _durationInMinutes) {
for (uint256 i = 0; i < _candidateName.length; i++) {
candidates.push(Candidate({name: _candidateName[i], voteCount: 0}));
}
owner = msg.sender;
votingStart = block.timestamp;
votingEnd = block.timestamp + (_durationInMinutes * 1 minutes);
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function addCandidate(string memory _name) public onlyOwner {
candidates.push(Candidate({name: _name, voteCount: 0}));
}
function vote(uint256 _candidateIndex) public {
require(!voters[msg.sender], "You have already voted.");
require(
_candidateIndex < candidates.length,
"Invalid candidate index."
);
candidates[_candidateIndex].voteCount++;
voters[msg.sender] = true;
}
function getAllVotesOfCandiates() public view returns (Candidate[] memory) {
return candidates;
}
function getVotingStatus() public view returns (bool) {
return (block.timestamp >= votingStart && block.timestamp < votingEnd);
}
function getRemainingTime() public view returns (uint256) {
require(block.timestamp >= votingStart, "Voting has not started yet.");
if (block.timestamp >= votingEnd) {
return 0;
}
return votingEnd - block.timestamp;
}
}
Deploy Script :
const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
module.exports = buildModule("VoteModule", (m) => {
const Candidates = ["Atharva", "Pratham"];
const Time = 120;
const vote = m.contract("Voting", [Candidates, Time]);
return { vote };
});
Error:
Batch #1
Executing VoteModule#Voting...
An unexpected error occurred:
IgnitionError: IGN1: Internal Hardhat Ignition invariant was violated: Expected failed simulation after having failed to estimate gas
at assertIgnitionInvariant (C:UsersHPOneDriveDesktopsamplenode_modules@nomicfoundationignition-coresrcinternalutilsassertions.ts:9:11)
at sendTransactionForOnchainInteraction (C:UsersHPOneDriveDesktopsamplenode_modules@nomicfoundationignition-coresrcinternalexecutionfuture-processorhelpersnetwork-interaction-execution.ts:156:28)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at sendTransaction (C:UsersHPOneDriveDesktopsamplenode_modules@nomicfoundationignition-coresrcinternalexecutionfuture-processorhandlerssend-transaction.ts:86:18)
at FutureProcessor.processFuture (C:UsersHPOneDriveDesktopsamplenode_modules@nomidules@nomicfoundationignition-coresrcinternalexecutionexecution-engine.ts:153:30)
at ExecutionEngine.executeModule (C:UsersHPOneDriveDesktopsamplenode_modules@nomicfoundationignition-coresrcinternalexecutionexecution-engine.ts:114:25)
at Deployer.deploy (C:UsersHPOneDriveDesktopsamplenode_modules@nomicfoundationignition-coresrcinternaldeployer.ts:194:25)
at SimpleTaskDefinition.action (C:UsersHPOneDriveDesktopsamplenode_modules@nomicfoundationhardhat-ignitionsrcindex.ts:302:24)
at Environment._runTaskDefinition (C:UsersHPOneDriveDesktopsamplenode_moduleshardhatsrcinternalcoreruntime-environment.ts:359:14)
Please suggest me any solution.
I am able to deploy the core contract of hardhat with the already written script on sepolia testnet.
New contributor
Atharva Dankhade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.