[Ethereum] Remix always throws the error: exceeds block gas limit

compilationgasistanbulremixsolidity

Dear Ethereum developers.

I started to learn Solidity this week and am trying to deploy a contract via Remix, but this doesn't really work.

Running environment is set as Web3 Provider.

(Because the book I am currently reading for studying Solidity asks me to do so, so I can learn about web3.js as well)

Here is my code:

pragma solidity ^0.4.24;
contract MyToken {
    string public name;
    string public symbol;
    uint8 public decimals;

    mapping (address => uint256) public balanceOf;
    event Transfer(address _from, address _to, uint _value);

    constructor(string tokenName, string tokenSymbol, uint8 decimalUnits, uint256 initialSupply) public {
        name = tokenName;
        symbol = tokenSymbol;
        decimals = decimalUnits;
        balanceOf[msg.sender] = initialSupply;
        }

    function transfer(address _to, uint256 _value) public {
        require(_value <= balanceOf[msg.sender]);
        require(balanceOf[_to] + _value >= balanceOf[_to]);
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);
    }
}

This is the whole code of my contract, and when I deploy this onto Remix then it keeps returning an error saying "it exceeds block gas limit".

I have adjusted the value of gas limit hundreds times and retried but it still doesn't work.

I also searched similar questions from this site and on the other sites too but nothing really helped.

One of my friends found that this contract can be deployed on Metamask with gas limit 404941 with value 1 gwei, so I have tried the same on Remix but it doesn't work.

Any help I can use?

Thanks in advance!

Best Answer

This is because gas used exceed your chain's block gas limit; to avoid it you can see what is the current block gas limit and increase it higher than gas used to deploy the smart contract

Related Topic