Search code examples
blockchainethereumsoliditysmartcontractsremix

address.call.value(amount)( ) method is not working with me


I've written a very simple method in solidity to send Ethereum to account but unfortunately it is not working

(ALREADY TRIED SEND AND TRANSFER METHOD)

function sendByCallValue(address payable _receiver, uint _amount) public payable {
    (bool success, ) = _receiver.call{value:_amount}("");
    require(success, "Transfer failed.");
}

I'm calling this function from REMIX IDE by passing an address and amount but it is throwing error.

In pic you will find this:

to : NftStaker.sendByCallValue(address,uint256) 0xEf9f1ACE83dfbB8f559Da621f4aEA72C6EB10eBf

which I think should be like this

to : 0xEf9f1ACE83dfbB8f559Da621f4aEA72C6EB10eBf

I'm not sure which thing is throwing error.

enter image description here

enter image description here


Solution

  • The transaction output shows that you're passing 0 wei along with the transaction, and trying to send 10 wei from the contract address.

    It doesn't show how much the contract owns, but assuming it's less than 10 wei, the transaction fails because the .call() is trying to send from the contract more than it owns.

    You can specify the value to send along with the transaction in the "Deploy & run transactions" of the Remix IDE.