I am trying to reward a user for typing a review:

function addReview(..., address payable _to) external payable {
    ... // code for adding a review including check for reentrency attacks
    payable(msg.sender).transfer(msg.value + 1);

This throws an "internal contract error". Using Ganache, MetaMask, Solidity 0.8.0.

What am I doing wrong?

Also, I want to transfer the funds from the smart contract's address.

Tried: using the Feeless library, using refundGasCost modifier (most of it was deprecated and failed when trying to fix).


This is my frontend code that calls this function:


addReview = (id, name, description, rating, codeToSubmit, timeAdded, account) => {
        this.setState({ loading: true })
        this.state.review.methods.addReview(id, name, description, rating, codeToSubmit, timeAdded, account).send({ from: this.state.account }).on('transactionHash', (hash) => {
            this.setState({ loading: false })
  • The code posted works without issues. The error should be in the code that wasn't shared. – Ismael Feb 27 at 20:42
  • You're actually right. Apologies for that. The code indeed doesn't give any errors. However, it doesn't "refund" the user's fees. The error is actually thrown when I attempt to fully refund with the additional gas fees (which I remember being 29700 from some other posts). Therefore I'm trying to transfer msg.value + 297000. I will edit my question now – Eric Feb 27 at 20:52
  • The transferred ethers are are from the contract balance. If it doesn't have enough for the msg.value + 297000 it will revert. – Ismael Feb 27 at 20:59
  • Thank you, but I tried to set it to 1 instead of 29700, and it still throws an error. I edited my question to include the frontend code. The error is thrown by MetaMask. It lets me confirm the transaction when I see a red ALERT, then after I confirm the transaction it gets reverted as you already suspected. – Eric Feb 27 at 21:08
  • I suspect it has something to do with transfer being deprecated in sol 0.8.0, but I'm not entirely sure, hence the question – Eric Feb 27 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.