Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling a payable method with correct ABI throws "Error: Can not send value to non-payable contract method or constructor" #1514

Closed
tricdc opened this issue Apr 1, 2018 · 1 comment

Comments

@tricdc
Copy link

tricdc commented Apr 1, 2018

I am trying to call releaseFunds():

    function releaseFunds() payable public{
        require(msg.sender == buyer || msg.sender == seller);
        require(msg.value == getOraclizePrice());
        require(paidFor);
        bytes32 id = oraclize_query("URL", [my query url], gasLimit);
        callbacks[id] = 0x04;
    }
    
    function releaseFunds_callback(string result) private{
        if(bytes(result).length == 0){}
        else status = byte(bytes32(stringToBytes32(result)));
        if(status == 0x34){
            uint256 amountToTransfer = price;
            price = 0;
            seller.transfer(amountToTransfer);
            emit FundsReleased();
        }
    }
    
    function __callback(bytes32 myid, string result) public{
        require(msg.sender == oraclize_cbAddress());
        if(callbacks[myid] == 0x01) addTrackingNumber_callback(result);
        else if(callbacks[myid] == 0x02) buyerCancel_callback(result);
        else if(callbacks[myid] == 0x03) updateTracking_callback(result);
        else if(callbacks[myid] == 0x04) releaseFunds_callback(result);
    }

My ABI:

	{
		"constant": false,
		"inputs": [],
		"name": "releaseFunds",
		"outputs": [],
		"payable": true,
		"stateMutability": "payable",
		"type": "function"
	}

Here's the Javascript code:

        contract.methods.releaseFunds().send({
            from: accounts[0],
            value: oraclizeFee
        })
        .on('error', function(error){
            setProgressBar("error");
        })
        .on('transactionHash', function(txHash){
            transactionHash = txHash;
            setProgressBar("half");
        })
        .on('confirmation', function(confirmationNumber, receipt){
            setProgressBar("full");
            statusText.innerText = "Transaction complete.";
        });

The error I get:

Uncaught (in promise) Error: Can not send value to non-payable contract method or constructor
    at Object.d._executeMethod (web3.min.js:1)
    at <anonymous>:1:41

I am using MetaMask as my Web3 provider on x64 Windows 10 in Google Chrome. This is on the Kovan testnet.

When I call the same method in Remix, the transaction goes through just fine.

@tricdc tricdc closed this as completed Apr 1, 2018
@tricdc
Copy link
Author

tricdc commented Apr 1, 2018

Forgot to update other important contract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant