0

I just coded ether transfer function using REMIX IDE on Ropsten testnet.
It has only two functions that setting receiver address and amount of ether and sending ether to receiver address.

After I deploy the contract and run the "transfer" function, it shows me error like below.

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:1401895 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:931969 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:350331 at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:368562) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353161 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:350331 at c (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353437) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353475 at Ht (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:362844) at Object. (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353564) at e.value (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:932884) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:932451 at n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:368506) at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:368584) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353161 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:932417 at n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:368506) at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:368584) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353161 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:932790 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353971 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:350331 at c (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353437) at s (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353359) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353161 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:353951 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:932672 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:931109 at i (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1070338)

And my code is this.

pragma solidity ^0.4.16;

contract test {

    address public receiver;
    uint public amount;

    function test(address _receiver, uint _amount) public {
        receiver = _receiver;
        amount = _amount;
    }

    function () public {
        receiver.transfer(amount);
        }
}

please help me.

Thanks.

  • 1
    Have you already called test to set the amount and receiver? – Raghav Sood Aug 2 '18 at 9:55
  • @RaghavSood Yes of course. when deploy the contract, set the receiver address and amount. – Ingyun Son Aug 2 '18 at 9:59
0

Your fallback function is not marked payable.

Since it is not payable, although you set the receiver and the amount, you cannot actually send that much ether to the contract to complete the transfer defined within the fallback function.

Adding payable fixes the contract:

pragma solidity ^0.4.16;

contract test {

    address public receiver;
    uint public amount;

    function test(address _receiver, uint _amount) public {
        receiver = _receiver;
        amount = _amount;
    }

    function () payable public {
        receiver.transfer(amount);
    }
}
  • adding payable does not work also. error message is below. transact to test.(fallback) errored: Error: gas required exceeds allowance or always failing transaction – Ingyun Son Aug 2 '18 at 10:12
  • Are you sending the required amount of ether along with the transaction? You cannot transfer ether if the contract does not have any. – Raghav Sood Aug 2 '18 at 10:12
  • do you mean on my contract? or deploying address? – Ingyun Son Aug 2 '18 at 10:14
  • In the transaction where you call the fallback function. – Raghav Sood Aug 2 '18 at 10:17
  • The problem solved! The contract should have some ethers for transfer to receiver. After send some ether to contract, the fallback function works fine. Thanks ! – Ingyun Son Aug 2 '18 at 10:20

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.