I made a smart contract, but i got an error while deploying it , after i specified the Gas limit of 3000000 and a random value (wei) , and clicking on Create , i got the following error :

( i am using Remix IDE , Metatmask extension and Ropsten the network . I have 10 Eth in my balance and I tried with solidity compiler 0.4.9 and 0.4.20 as well but still getting the same error)

Error :

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? 
Error: gas required exceeds allowance or always failing transaction at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1391377 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:927906 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:346093 at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:364324) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:348923 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:346093 at c (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:349199) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:349237 at Ht (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:358606) at Object.<anonymous> (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:349326) at e.value (chrome-

This my code :

pragma solidity ^0.4.21;

contract admined{
    address public admin;

    function admined(){
        admin = msg.sender;

    modifier onlyAdmin(){
        require(msg.sender == admin);

    function transferAdminRol(address newAdmin)public onlyAdmin {
        admin = newAdmin;


contract ERC20{

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    string public standard = "Test Africa v0.1";
    string public name;
    string public symbol;
    uint8 public decimal; 
    uint256 public totalSupply;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    function ERC20(uint256 initialSupply, string _name, string _symbol, uint8 _decimal) public{
        balanceOf[msg.sender] = initialSupply;
        name = _name;
        symbol = _symbol;
        decimal = _decimal;
        totalSupply = initialSupply;

    function transfer(address _to, uint256 _value)public returns (bool success){
       require(balanceOf[msg.sender] >= _value);
       require(balanceOf[_to] + _value >= balanceOf[_to]);

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);
        return true;

    function approve(address _spender, uint256 _value) public returns (bool success){
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;

    function allowance(address _owner, address _spender) public returns (uint256 remaining) {
      return allowance[_owner][_spender];
    function transferFrom(address _from, address _to, uint256 _value)public returns (bool success){
        require(balanceOf[_from] >= _value);
        require(balanceOf[_to] + _value >= balanceOf[_to]);
        require(_value <= allowance[_from][msg.sender]); 

        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        allowance[_from][msg.sender] -= _value;
        emit Transfer(_from, _to, _value);

        return true;

    function balanceOf(address _owner)public constant returns (uint256 balance) {
        return balanceOf[_owner];

contract testaAFC is admined, ERC20{

    uint public minBalanceForAccounts = 50000000000000 wei;

    uint256 public sellPrice = 500;
    uint256 public buyPrice = 500;

    bytes32 public currentChallenge;                         
    uint public timeOfLastProof;                             
    uint public difficulty = 10**32;                            

    mapping (address => bool) public frozenAccount;
    event FrozenFunds(address target, bool frozen);

    function testaAFC(uint256 initialSupply, string _name, string _symbol, 
            uint8 _decimal, address _admin)public  ERC20(0, _name, _symbol, _decimal){

        if(_admin != 0)
            admin = _admin;
            admin = msg.sender;

        balanceOf[admin] = initialSupply;
        totalSupply = initialSupply;


    function transfer(address _to, uint256 _value)public returns (bool success){

    function transferFrom(address _from, address _to, uint256 _value)public returns (bool success){

    function setMinBalance(uint minimumBalanceInFinney)public onlyAdmin {
         minBalanceForAccounts = minimumBalanceInFinney * 1 wei;

    function mintToken(address target, uint256 mintedAmount)public onlyAdmin {
        balanceOf[target] += mintedAmount;
        totalSupply += mintedAmount;
        emit Transfer(0, this, mintedAmount);
        emit Transfer(this, target, mintedAmount);

    function setPrices(uint256 newSellPrice, uint256 newBuyPrice)public onlyAdmin {
        sellPrice = newSellPrice;
        buyPrice = newBuyPrice;

    function buy()public payable returns (uint amount){
        amount = msg.value * buyPrice;                   
        require(balanceOf[this] >= amount);               
        balanceOf[msg.sender] += amount;                  
        balanceOf[this] -= amount;                        
        emit Transfer(this, msg.sender, amount);               
        return amount;                                  

    function sell(uint amount)public returns (uint revenue){
        require(balanceOf[msg.sender] >= amount);         
        balanceOf[this] += amount;                        
        balanceOf[msg.sender] -= amount;                  
        revenue = amount / sellPrice;                     
        emit Transfer(msg.sender, this, amount);             
        return revenue;                                 



  • which contract you are trying to deploy? – Aniket May 2 '18 at 13:14
  • I successfully deployed testaAFC contract using metamask & Remix on Ropsten. – Aniket May 2 '18 at 13:24
  • can you tell me how did you do it ? – Abdeljalil HALLOUMI May 2 '18 at 13:28
  • I just pasted your contract, provided constructor parameters and it worked like charm. – Aniket May 2 '18 at 13:30
  • what value you used and what's your configuration ?? – Abdeljalil HALLOUMI May 2 '18 at 13:33

There is no need to put any value in value field unless you are looking to transfer some ETH along with your transaction. Also keep remember using payable keyword in any such case.

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.