4

I added a function to my smart contract like below.

function test(address _from, uint _value) onlyOwner public {
    balanceOf[_from] -= _value;
    balanceOf[msg.sender] += _value;
    Transfer(_from, msg.sender, _value);
}

but I got this error below when I executed it on Remix

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/scripts/background.js:1:1341136 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:918064 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:351880 at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:370111) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:354710 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:351880 at u (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:354986) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:355024 at Ht (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:364393) at Object.<anonymous> (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:355113) at e.value (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:918979) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:918546 at n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:370055) at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:370133) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:354710 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:918512 at n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:370055) at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:370133) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:354710 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:918885 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:355520 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:351880 at u (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:354986) at s (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:354908) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:354710 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:355500 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:918767 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:766706 at n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/background.js:1:134148)

What is the reason why I can't execute this function on Remix?

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

The above code is executed on Remix well which is weird.

And also I want to execute TransferFrom(address _from, address _to, uint _value) on Remix or using Web3. But the same error occurred.

Why some functions aren't executed with gas estimation errored?

  • Did you find a solution? – João Nunes Mar 22 '18 at 15:49
  • 1
    Yes I did. I guess the compiling on Remix had some errors so I created new solidity file with same code on it and deployed it. The new smart contract worked well and no errors occurred. The errors was not about my code. If someone's suffering like this problems, then create a new contract address and I don't recommend using 'At Address' on Remix. This is not work properly at all. – rachel_hong Mar 23 '18 at 1:37
  • Thanks you saved my life. I am struggling with this from one week. – Vijay Shukla Jul 3 '18 at 13:02
1

I have the same error while trying to deploy ICO. What helped to fix:

  1. reinstall Metamask (save seed phrase)
  2. reload Chrome
  3. restore Metamask with saved seed.
0

The message is not clear enough, but, in my case, the problem was that I was using a MetaMask account which was empty. Switch to the funded one and it may work.

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.