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.


     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);


   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);


"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"}




   Replacing 'Migrations'


   Replacing 'Election'
   Error: Error: Error:  *** Deployment Failed ***


   rinkeby: {
  host: "",     // Localhost (default: none)
  port: 8545,            // Standard Ethereum port (default: none)
  network_id: "4",       // Any network (default: none) (Rinkeby's id 
   is given)
  gas: 3000000  
  • Can you show me the code of your genesis file? – Prachi Sharma Aug 23 '19 at 19:17
  • @Prachi Sharma I edited my question and i added genesis file – jhdm Aug 23 '19 at 19:30
  • @Prachi Sharma i dont understand how can estimate gas value in truffle-config.I mean what should i write gas: value in truffle-config – jhdm Aug 23 '19 at 19:32

This error is not associated with the Gas value.

You need to set byzantiumBlock in the config section of your genesis.json file.

"config": {
    "chainId": 88888,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0

Since your genesis file has been updated now, you need to create new node and new address. And then try migrating your contracts with that account.

About the estimation of Gas value, what you can do is deploy the contract on Remix first. Try providing the Gas value there. If it deploys successfully, that means the Gas value is okay.

Edited Answer:

Transaction exited after consuming all gas:

This issue is related to the fact that truffle is using solidity compiler 0.5.8 which causes an issue of interaction with contracts.

I faced the same issue. Downgrading Truffle from v5.0.30 to v5.0.5 fixed the issue.

npm i -g truffle@v5.0.5

And then used solidity version ^0.5.0 in both Migrations and Election contract.

Provide gas: 3000000 in your truffle-config.js file.

  • I added byzantiumBlock and try to migrate contract it throws exception again. Saving migration to chain.Error: Error: StatusError: Transaction: exited with an error (status 0) after consuming all gas. – jhdm Aug 23 '19 at 20:20
  • it starts to throw exception again "Migrations" exceeded the block limit (with a gas value you set). * Block limit: 0x1ff60d2 * Gas sent: 8500000 – jhdm Aug 23 '19 at 20:51
  • when i enter the gas value sometimes gives error like exceeded block limit and sometimes whne change the value exited with an error after consuming all gas. – jhdm Aug 23 '19 at 21:10
  • Which truffle version you are using? – Prachi Sharma Aug 24 '19 at 3:15
  • I've edited the answer for same. – Prachi Sharma Aug 24 '19 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.