When I use the variable minimum in the require statement
require(msg.value >= minimum, "Below Minimum");
I get the below error in Remix. However, if I hardcode the require statement with 0 instead of minimum everything works. Why?
transact to SendContractEther.sendEtherToContract 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 am sending Ether to contract King from contract SendContractEther.
Thank you for an explanation for this behavior.
// SPDX-License-Identifier: MIT
pragma solidity 0.7.4;
contract King {
uint public minimum;
address payable public owner;
constructor() payable {
owner = msg.sender;
minimum = 0;
}
receive () external payable {
require(msg.value >= minimum, "Below Minimum");
owner.transfer(msg.value);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.7.4;
contract SendContractEther {
address payable public contractAddress ;
// Assign the address of the Contract
constructor(address payable _contractAddress) payable {
contractAddress = _contractAddress;
}
function sendEtherToContract() external payable {
contractAddress.transfer(address(this).balance);
}
}