Hi i am trying to work truffle migrate and firstly it start to Migration.sol and then Election.sol. When start to deploy ELection.sol it throws following error. What should i write gas:270000 instead of this value?Because i tried a lot of number like 470000 or 100000, 300000 doesnt work. Should i increase number or decrease?
truffle migrate --reset --network rinkeby
"Election" received a generic error from Geth that can be caused by hitting revert in a contract constructor or running out of gas. * Returned error: gas required exceeds allowance (2700000) or always failing transaction.
Election.sol
pragma solidity 0.5.8;
contract Election {
// Model a Candidate
struct Candidate {
uint id;
string name;
uint voteCount;
}
// Read/write Candidates
mapping(uint => Candidate) public candidates;
// Store Candidates Count
uint public candidatesCount;
constructor() public {
addCandidate("Candidate 1");
addCandidate("Candidate 2");
}
function addCandidate (string memory _name) private {
candidatesCount ++;
candidates[candidatesCount] = Candidate(candidatesCount, _name, 0);
}
}
Migrations.sol
pragma solidity >=0.4.21 <0.6.0;
contract Migrations {
address public owner;
uint public last_completed_migration;
constructor() public {
owner = msg.sender;
}
modifier restricted() {
if (msg.sender == owner) _;
}
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
Genesis.file
{
"config": {
"chainId": 88888,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x1",
"extraData" : "0x00",
"gasLimit" : "0x47e7c5",
"nonce" : "0x0000000000000042",
"timestamp" : "0x00",
"alloc" :{
"0x560ae6e63f0e79c9027a590900291399cc954f00": {"balance": "0xffffffffffffffffffffffff"}
}
}
Output:
1_initial_migration.js
======================
Replacing 'Migrations'
.......
then
2_deploy_contracts.js
=====================
Replacing 'Election'
Error: Error: Error: *** Deployment Failed ***
truffle.config
rinkeby: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "4", // Any network (default: none) (Rinkeby's id
is given)
from:"address",
gas: 3000000
}