1

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!

  • To what kind of network is your MetaMask connected? Are you running a Geth node? Ganache? Truffle? Infura maybe? – Henk Aug 20 '18 at 13:20
  • Geth I bet. I have never used any others but geth. – Auclown Aug 21 '18 at 2:40
  • geth --datadir "private-data" --networkid 15 --rpc --rpcapi "db,eth,net,web3,perosnal,miner" --rpccorsdomain "*" console This is exactly what I typed on cmd before I set the running environment as Web3 Provider. – Auclown Aug 21 '18 at 3:06
0

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

  • Thanks for replying, but can you please tell me how I can check the gas limit and adjust it? I think it is the thing that I can see under "Run" tab of Remix, but as I wrote in my question it didn't really work. – Auclown Aug 20 '18 at 13:13
  • you can run this cmd on the console eth.getBlock("latest").gasLimit; – Ha ĐANG Aug 20 '18 at 13:14
  • And because run choose connect to node by using Running environment is set as Web3 Provider. then as Henk mentioned above, what is your node that you connecting to? – Ha ĐANG Aug 20 '18 at 14:02
  • geth --datadir "private-data" --networkid 15 --rpc --rpcapi "db,eth,net,web3,personal,miner" --rpccorsdomain "*" console Maybe you mean this? network id 15. That is exactly what I typed on cmd – Auclown Aug 21 '18 at 3:00
  • so what is the output by running eth.getBlock("latest").gasLimit; on console of your network? – Ha ĐANG Aug 21 '18 at 3:04
0

enter image description here I am able to deploy the same contract on the remix. Check your Gas limit while deploying contract if it is more or equal to 3000000 then you should be able to deploy the contract.

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.