1

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  
 }
3
  • Can you show me the code of your genesis file? Aug 23, 2019 at 19:17
  • @Prachi Sharma I edited my question and i added genesis file
    – jhdm
    Aug 23, 2019 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, 2019 at 19:32

1 Answer 1

0

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 [email protected]

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

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

11
  • 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, 2019 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, 2019 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, 2019 at 21:10
  • Which truffle version you are using? Aug 24, 2019 at 3:15
  • I've edited the answer for same. Aug 24, 2019 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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