1

Problem summary

I get the following error whenever I try transferring ether from an EOA(externally owned account) to a contract account in one of my functions as seen below. I am currently using the contract-upgradability pattern. The snippet below is from the data-contract

function fund (uint value, address sender) external payable {
   ...
    // Transfer value to contract balance
    address payable contractAcct = payable(address(this)); 
    // DAO.transfer(value);
    (bool success,) = contractAcct.call{value: value, gas:4000}("");
    require(success, "Pay to account was not successful");
}

The snippet below shows how I call the function above from my app-contract

function fundAirline() public payable{
  // flightSuretyData is the interface of the data-contract.
    flightSuretyData.fund(msg.value, msg.sender);
}

Finally, this is how I call the function from my test cases.

// Fund first airline
    await config.flightSuretyApp.fundAirline({from: config.firstAirline, value: web3.utils.toWei('10','ether') });

What I tried

I failed when I first tried using the address.transfer() method to transfer the ether over to the contract account. After a couple of articles, I was led to believe that using the call method as seen above, is the best way to transfer funds to an account because you get the benefit of checking if the transfer passes or not.

Long story short, I am still stuck in this position. Any guide will be highly appreciated. Thanks in advance.

5
  • If you expect it to send eth, the call to fund() should pass a value, like this: flightSuretyData.fund{value: msg.value}(msg.value, msg.sender); and the 'contractAcct' should have a payable fallback or receive method in order to receive it May 28, 2022 at 18:52
  • Just tried your suggestion and I still get the same error, though your solution is really interesting because I haven't come across any material that suggested it as such. If possible, could you please provide me with resources to research further?
    – mbappai
    May 28, 2022 at 19:12
  • Sure, check this for instance: docs.soliditylang.org/en/latest/… May 28, 2022 at 19:20
  • Thanks a lot Dr.Gorilla, I really appreciate your help.
    – mbappai
    May 28, 2022 at 19:52
  • Nice! Just posted it, thx! Jun 2, 2022 at 14:21

1 Answer 1

2

I see 2 possible issues:

  • flightSuretyData.fund(msg.value, msg.sender); I guess this call should send eth (based on the name and the args, you should therefore pass the value to send, like this: flightSuretyData.fund{value: msg.value}(msg.value, msg.sender);
  • in order for the eth transfer (via call(..)) to contractAcct to succeed, it needs to implement a receive() or fallback()

See the solidity docs for more info on managing eth transfers: https://docs.soliditylang.org/en/latest/security-considerations.html?highlight=call%20with%20value#sending-and-receiving-ether

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.