0

I have ran into a strange problem. I get an 'Error: non-payable method cannot override value' when I try to send some ethereum to the smart contract via the transfer function. Here is the smart contract logic excerpt:

constructor() payable {
    owner = msg.sender;
  }
function deposit(address _seller) external payable returns(bytes32) {

   require(msg.value > 0.1 ether, "Value of the deposit must be more than 0.1 ether"); 
}

And this is the UI code excerpt:

function blockchainTalk(e) {
  e.preventDefault();
  contract.deposit("0xF025B4AC25D5DC1FfD77B099a31ddc269D55c039", {gasLimit: 5000000, value: ethers.utils.parseEther("1.0")});
}

However, I am not able to transfer to my smart contract, as I get the "Error: non-payable method cannot override value".

Please help me out <3

Edit: Upon request, sharing the full contract:

pragma solidity ^0.8.4;

contract Escrow {

  address owner;

  struct Deposit {
      uint256 depositAmount;
      address buyer;
      address seller;
      bool executed;
  }

  constructor() payable {
    owner = msg.sender;
  }

  mapping(bytes32 => Deposit) public depositByHash; 

  event DepositMade(address buyerAddress, address sellerAddress, uint depositAmount, bytes32 hash);
  
  function deposit(address _seller) external payable returns(bytes32) {

    require(msg.value > 0.1 ether, "Value of the deposit must be more than 0.1 ether"); 

    bytes32 hash = keccak256(abi.encode(msg.value, block.timestamp, _seller)); 

    Deposit storage _deposit = depositByHash[hash]; 

    _deposit.depositAmount = msg.value; 

    _deposit.buyer = msg.sender;
    
    _deposit.seller = _seller;  

    emit DepositMade(msg.sender, _seller, msg.value, hash);

    return hash; 
  }

  function releaseDepositToBuyer(bytes32 hash) external returns(bool) {

    require(msg.sender == depositByHash[hash].buyer, "Only maker of the deposit can release deposit.");

    require(depositByHash[hash].executed == false, "The function can only be executed once.");

    payable(depositByHash[hash].seller).transfer(depositByHash[hash].depositAmount);

    return depositByHash[hash].executed = true;
  }

  function divineIntervention(address payable _to, uint _amount) external payable {

    require(
      msg.sender == owner,
      "This function can only be called by the creator of the contract"
    );

    // This might be unsafe against re-entrancy attack. 
    // Possible there is a safer alternative.
    
    _to.transfer(_amount);
  }
}

And here is the full React App code (the contract is deployed to a local Hardhat node):

import React, {useState, useEffect} from 'react';
import { ethers } from "ethers";

function App() {

const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()
const contractAddress = "0x5fbdb2315678afecb367f032d93f642f64180aa3"

const ABI = [
  "function deposit(address _seller)"
];

const contract = new ethers.Contract(contractAddress, ABI, signer);

async function isConnected() {
  const accounts = await window.ethereum.request({method: 'eth_accounts'});       
  if (accounts.length) {
     console.log(`You're connected to: ${accounts[0]}`);
  } else {
     console.log("Metamask is not connected");
  }
}

useEffect(() => {
  async function connectWallet() {
  await provider.send("eth_requestAccounts", []);
  }
  connectWallet()
    .catch(console.error)
  isConnected()

function blockchainTalk(e) {
  e.preventDefault();
  contract.deposit("0xF025B4AC25D5DC1FfD77B099a31ddc269D55c039", {gasLimit: 5000000, value: ethers.utils.parseEther("1.0")});
}
}
4
  • 1
    How was deposit declared in the base contract? Is it also payable?
    – Ismael
    Commented Dec 19, 2022 at 20:34
  • Yes sir, I did include the deposit declaration in my question: function deposit(address _seller) external payable returns(bytes32)
    – sunsakis
    Commented Dec 19, 2022 at 20:58
  • Can you share the whole contract? or at least some that could be compiled and tested to reproduce the error.
    – Ismael
    Commented Dec 19, 2022 at 21:19
  • @Ismael updated the question to include the full smart contract and React app logic.
    – sunsakis
    Commented Dec 19, 2022 at 21:31

2 Answers 2

2

Maybe your ABI is corrupted, make sure your abi is correct and matches your contract

2
  • yes that ABI is off upon your edit thank you Commented Dec 19, 2022 at 21:35
  • Indeed, I needed to include "payable" in the ABI! It's the first time I'm using ABI, I thought human readable ABI does not need me to include "payable" in it and that it is enough to only have it in the smart contract!
    – sunsakis
    Commented Dec 19, 2022 at 21:35
0

Inorder to receive ether you have to have this

 receive() external payable{}

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.