0

Hope everyone's doing well.

For the past few days I've been having issues with a payable function which I know is definitely working. How do I know it's working? Ether gets sent successfully on Remix.

The following code is from a section of my contract:

function payRent()   
public   
payable   
onlyTenant   
inState(State.Started)   
equalValue   {
        landlord.transfer(msg.value);
        paidrents.push(PaidRent({
        id : paidrents.length + 1,
        value : msg.value
        }));   }

Assume that landlord is an address which was previously stated within the contract.

I have also included the fallback payable function:

  //fallback payable
  function() public payable{}

The above functions work perfectly with Remix. I have created a React Application which would call this function and use the Metamask as the web3 provider. Within the function I use the return section as so:

return rentalAgreementInstance.payRent.sendTransaction({from: accounts[0], value: this.state.web3.toWei(this.state.rent, "ether"), gas:30000})

Instance has been properly initialized.

This is set to activate on a button click.

Everytime the button is clicked, Metamask provides me with a popup to confirm the transaction with the proper value defined. Now the issue arises once confirm is clicked.

The transaction gets completed, but no ether is deducted from the sender account, and no ether is received by the receiving account.

I assume I may be calling it incorrectly within the web3 return function of react.

If any more relevant details are required please let me know.

Some help would really be appreciated. Thank you all!

5
  • Can you share the tx on etherscan?
    – Davide C
    Commented Mar 24, 2018 at 8:27
  • Does the metamask popup show the correct amount? Can you log what value has this.state.rent?
    – Ismael
    Commented Mar 24, 2018 at 15:40
  • Yes the correct amount is shown. this.state.rent is a value which can be set by the contract creator. Keep in mind I'm using a private node, Ganache specifically. Commented Mar 24, 2018 at 22:18
  • Does the transaction succeed? If you query the transaction receipt what is the status? If it fails perhaps the gas is too low.
    – Ismael
    Commented Mar 25, 2018 at 17:14
  • Still haven't found a solution to this. And yes, the transaction succeeds. This is it works perfectly on Remix, but not on Metamask, still hoping for a solution for this. Commented Apr 1, 2018 at 0:20

1 Answer 1

2

So I've managed to solve the problem.

Ismael mentioned that the gas was too low.

I realized this when I created a truffle unit test for the payable transaction. Once the transaction was successful, I headed over to the Ganache client and noticed the gas required for the payment.

This made me realize that the gas I had given was too low. I changed it from 30000 to 100000 and it worked perfectly.

I hope someone else might find this answer useful too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.