我试图在合同之间发送一些以太币,但我得到这个错误:
事务已恢复到初始状态。注意:如果你发送值并且你发送的值应该小于你当前的余额,那么调用函数应该是支付的。调试事务以获取更多信息。
我的合同:
contract test {
address public owner;
address payable public receiverContract;
constructor(address payable _receiverContract) payable{
receiverContract = _receiverContract;
owner = msg.sender;
}
function sendEther() public payable {
receiverContract.transfer(msg.value);
}
receive() external payable {
}
}
接收者合约也有一个receive() external payable
函数,当我用一些以太调用sendEther()
时,在用一些以太播种测试合约后,我得到了错误
该消息表明您应该添加一个需求来测试用户是否确实拥有他试图发送到合约的以太币。
address public owner;
address payable public receiverContract;
constructor(address payable _receiverContract) payable{
receiverContract = _receiverContract;
owner = msg.sender;
}
function sendEther() public payable {
require(address(this).balance > msg.value, "Not enough funds" );
receiverContract.transfer(msg.value);
}
receive() external payable {
}
} ```