I am trying to run my smart contract in remix ide, below is my smart contract code:

pragma solidity >=0.4.17 <0.7.0;
pragma experimental ABIEncoderV2;
contract Department{

    struct Employee{
        uint empId;
        string empName;
        uint256 empSalary;

    uint departmentId;
    string departmentName;
    mapping (uint => Employee) public employees;
    uint public employeeCount;

    constructor(uint _departmentId, string memory _departmentName) public {
        employeeCount = 0;
        departmentId = _departmentId;
        departmentName = _departmentName;

    function addEmployee(uint _empId, string memory _empName, uint _empSalary ) public {
        employees[employeeCount] = Employee(_empId, _empName, _empSalary);

    //return Single structure
    function get(uint _index) public view returns(Employee memory) {
        return employees[_index];

    //return Array of structure Value
    function getEmployee() public view returns (uint[] memory, string[] memory, uint[] memory) {
        uint[]    memory id = new uint[](employeeCount);
        string[]  memory name = new string[](employeeCount);
        uint[]    memory salary = new uint[](employeeCount);
        for (uint i = 0; i < employeeCount; i++) {
          Employee storage employee = employees[i];
          id[i] = employee.empId;
          name[i] = employee.empName;
          salary[i] = employee.empSalary;
        return (id, name, salary);

    //return Array of structure
    function getEmployees() public view returns (Employee[] memory) {
        Employee[]  memory id = new Employee[](employeeCount);
        for (uint i = 0; i < employeeCount; i++) {
          Employee storage employee = employees[i];
          id[i] = employee;
        return id;


I am running private block wherein my miners are mining the blocks. I had my miners running all the time but they were adding empty blocks so I used --preload mineWhenNeeded.js flag and limit the miners to mine until 12 blocks using following code in my mineWhenNeeded.js

var minimum_confirmations = 12;
var mining_threads = 1
var txBlock = 0
function checkWork() {
    if (eth.getBlock("pending").transactions.length > 0) {
        txBlock = eth.getBlock("pending").number
        if (eth.mining) return;
        console.log("  Transactions pending. Mining...");
        interval = setInterval(function () {
            if (eth.getBlock("latest").number < txBlock + minimum_confirmations) {
                if (eth.getBlock("pending").transactions.length > 0) txBlock = eth.getBlock("pending").number;
            } else {
                console.log(minimum_confirmations + " confirmations achieved; mining stopped.");
        }, 600)

eth.filter("latest", function (err, block) { checkWork(); });
eth.filter("pending", function (err, block) { checkWork(); });


Here is my geth command

 geth --datadir $ethereum_home/chaindata --preload "scripts/mineWhenNeeded.js" --networkid 45638 --verbosity 6 --rpc --port 30304 --rpcport 8545 --rpcaddr "" --rpcapi "web3,eth,personal,net" --rpccorsdomain remix.ethereum.org --nodiscover --gcmode archive --allow-insecure-unlock console 2

But now after some time I am getting error Returned error: gas required exceeds allowance (8000000) or always failing transaction

After few experiments I realize that if I let my miners run for a while and check the limit of my latest block using following code eth.getBlock("pending").gasLimit in geth console, the limit is decreasing gradually. It seems like if I let my miners run all the time then I will not get that gas required exceeds allowance issue anymore. Now I am wondering, should I remove the restriction to mine only 12 blocks but it gonna start adding empty blocks again. What should I do?

  • What version of web3.js are you using? Looks like 0.x something. Mar 23, 2020 at 10:18
  • I am not using web3.js right now...for testing purpose only, I am using remix Ide to deploy my contract on my private chain
    – Ruchita
    Mar 23, 2020 at 10:33
  • And this code runs on Remix? Mar 23, 2020 at 10:59
  • I using geth console to run my private blockchain and this is my geth cmd: geth --datadir $ethereum_home/chaindata --preload "scripts/mineWhenNeeded.js" --networkid 45638 --verbosity 6 --rpc --port 30304 --rpcport 8545 --rpcaddr "" --rpcapi "web3,eth,personal,net" --rpccorsdomain remix.ethereum.org --nodiscover --gcmode archive --allow-insecure-unlock console 2 and I am running my smart contract in remix ide
    – Ruchita
    Mar 23, 2020 at 11:07
  • The code in your question is not a contract. How do you execute it? Mar 23, 2020 at 11:11

1 Answer 1


The block gas limit can be controlled by two geth command line options

  • --miner.gastarget value Target gas floor for mined blocks
  • --miner.gaslimit value Target gas ceiling for mined blocks

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.