CryptoFly.us | CRYPTOCURRENCY BITCOIN SHIRTS CLOTHING APPAREL HATS

CRYPTO NEWS

6 Questions for Yat Siu of Animoca Brands

"Election" hit an invalid opcode while deploying. truffle migrate

I’m just getting started with Solidity and ran into a problem that I can’t solve. The error below displays when you try to migrate truffle migrate –reset 2_deploy_contracts.js ===================== Replacing ‘Election’ ——————– Error: *** Deployment Failed *** "Election" hit an invalid opcode while deploying. Try: * Verifying that your constructor params satisfy all assert conditions.::Listen

I’m just getting started with Solidity and ran into a problem that I can’t solve. The error below displays when you try to migrate

truffle migrate --reset 
2_deploy_contracts.js =====================     Replacing 'Election'    --------------------  Error:  *** Deployment Failed ***  "Election" hit an invalid opcode while deploying. Try:    * Verifying that your constructor params satisfy all assert conditions.    * Verifying your constructor code doesn't access an array out of bounds.    * Adding reason strings to your assert statements. 

I do not understand why this is happening, I have tried many solutions, but still without effect. Updating the truffle version did not help, and neither did the subsequent changes to the Election.sol structure. I am using ganache v2.5.4

Election.sol

// SPDX-License-Identifier: MIT pragma solidity >=0.4.22 <0.8.20; pragma experimental ABIEncoderV2; contract Election {     struct Elections {         uint id;         string title;         string description;         uint creationDate;         uint expirationDate;         Candidate[] candidates;     }     uint public electionsCount;     Elections[] elections;      struct Candidate {         uint id;         string name;         uint voteCount;     }     uint public candidatesCount;      function addElections (string memory _title, string memory _description, uint _amountOfHours, string[] memory _names) private {         electionsCount ++;         elections[electionsCount].id = electionsCount;         elections[electionsCount].title = _title;         elections[electionsCount].description = _description;         elections[electionsCount].creationDate = block.timestamp;         elections[electionsCount].expirationDate = block.timestamp + _amountOfHours;          Candidate[] memory candidates;         for (uint i = 0; i < _names.length; i++) {             candidatesCount ++;             string memory name = _names[i];             candidates[candidatesCount] = Candidate(candidatesCount, name, 0);             elections[electionsCount].candidates.push(candidates[i]);         }     }     string[] names= ["AAAA", "BBBBB", "CCCCCC"];      constructor () public {         addElections("Voted", "vote for your candidate", 8, names);     } } 

6 Questions for Yat Siu of Animoca Brands

Shopping cart
There are no products in the cart!
Continue shopping
0