My deployed contract called successfully only by "function invocation" through web3 or Remix. But it always failed when I sending funds to the contract.

I thought that only requirement that contract has payable function but maybe it is not enough?

Contract looks like:

contract GetRandom is usingOraclize {
    event newRandomNumber(bytes);

    function GetRandom() {

    function __callback(bytes32 _queryId, string _result, bytes _proof) oraclize_randomDS_proofVerify(_queryId, _result, _proof) {
        // if we reach this point successfully, it means that the attached authenticity proof has passed!
        if (msg.sender != oraclize_cbAddress()) throw;


    function update() payable {
        uint N = 7; // number of random bytes we want the datasource to return
        uint delay = 0; // number of seconds to wait before the execution takes place
        uint callbackGas = 200000; // amount of gas we want Oraclize to set for the callback function

        // this function internally generates the correct oraclize_query and returns its queryId
        bytes32 queryId = oraclize_newRandomDSQuery(delay, N, callbackGas);

it always failed when I sending funds to the contract

This sounds as if you attempt to send Ether to the smart contract without any further data - and hence without calling any specific function. If you "just send Ether" to the smart contract, a special function without a name called fallback function is invoked. In your case, this fallback function also needs to have a payable modifier. If you do not implement a payable fallback function yourself, it is not possible to "just send Ether" to the smart contract.

| improve this answer | |

Throw this one in as the fallback, similar to what Sebastian said:

function() payable {}
| improve this answer | |
  • Throw what in the fallback? Why would this help? – 0xcaff Jul 16 '17 at 2:24
  • A fallback is just a blank function that is triggered when someone interacts with the contract without one of the other specified functions. So for instance if someone just sent money to the contract address, this fallback would just receive the funds in the contract – thefett Jul 16 '17 at 16:49
  • Isn't there a gas limit on fallback function execution? – 0xcaff Jul 16 '17 at 22:05

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.