I am trying to transfer some Ether between two contracts but it is just not working for me. Here is my code:
pragma solidity ^0.6.0;
contract ContractA {
uint public tips;
/**
* Function to collect the tips.
*/
function collectTips(address payable _recipient) public {
require(_recipient.send(tips));
tips = 0;
}
/**
* Receive function in order to receive tips. No calldata is set
*/
receive () external payable {
tips += msg.value;
}
}
contract ContractB {
uint256 public tips;
/**
* Receive function in order to receive tips. No calldata is set
*/
receive() external payable {
tips += msg.value;
}
}
Whenever I send a transaction to collectTips
, giving the contract address of ContractB
I get the following error in remix
transact to ContractA.collectTips errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
I was referring to these docs: https://docs.soliditylang.org/en/v0.6.0/contracts.html#receive-ether-function
I am clueless. Anyone an idea what I am doing wrong?
I found also sort of the same question around here, but nothing helped. Either the Solidity version is too old or just not working for me :/
Best and thanks in advance