0

Just learning Solidity here. I am trying to pass an receiving address, and an arbitrary amount (other than msg.value) to my transfer function, but it is just not working for me. This is the code:

pragma solidity 0.8.7;

contract TestingTransfer{

uint approvalCount = 1;
uint approvalMinimum = 2;
uint originalAmount;
address payable originalReceiver;

constructor(address payable _oRec, uint _oA){
    originalReceiver = _oRec;
    originalAmount = _oA;
}

function approveTransferRequest() public payable {
    approvalCount += 1;
    
    if(approvalCount >= approvalMinimum){
        (bool success,  ) = originalReceiver.call{value: msg.value}("");
        require(success, "Failed to transfer the funds, aborting.");
    }
}

}

Ok, so that code works great when I use the remix value input box, and manually enter whatever eth amount I want to transfer. However, my endgoal is to have the if statement produce this:

    function approveTransferRequest() public payable {
    approvalCount += 1;
    
    if(approvalCount >= approvalMinimum){

        (bool success,  ) = originalReceiver.call{value: originalAmount}("");
        require(success, "Failed to transfer the funds, aborting.");
    }
}

Where the argument for the call method is 'originalAmount' which was passed from another function. However, the compiler does not like this, and reverts my function every time.

I'd appreciate any suggestions :)

0
0

A contract can send up to address(this).balance, if it doesn't have enough ether it will revert. You can either send with the function, or transfer ethers from another account.

For a contract to accept ether transfer it has to implement the receive function

receive() external payable {
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.