Why doesn't this work on remix? It compiles the contract but when you execute 'f' it reverts back the tx and sends the error message.

pragma solidity 0.8.7;

contract Testing44{

uint256 amount = 1000000000000000000;
address payable recipient;

constructor(address payable _addr){
    recipient = _addr; 

function f() public payable {
    //require(msg.value == amount, 'error msg');

  • 1
    My guess is that the contract doesn't have enough balance to transfer Sep 24 '21 at 18:26
  • Yes, I agree completely. I'm using the remix IDE and using the dummy addresses that come with it. When I run address(this).balance, it returns 0. But I have no way to add fake value to the address, is there a way to add this fake value? Sep 24 '21 at 18:38
  • It's not very fake, since you are using the native asset of the blockchain you are interacting with - your account just happens to have lots of the asset in advance. Anyway, you can simply send the value to the function, since it's payable Sep 24 '21 at 18:43
  • implement a recieve() function (it can be empty) and send your contract ETH
    – Foxxxey
    Sep 24 '21 at 20:05
  • Oh wait, you're expecting recipient.transfer() to send your eth to the contract?
    – Foxxxey
    Sep 24 '21 at 20:06