[英]solidity transaction error, The called function should be payable if you send value and the value you send should be less than your current balance
[英]Solidity transaction error: The called function should be payable if you send value and the value you send should be less than your current balance
我試圖在合約之間發送一些以太幣,但我收到了這個錯誤:
交易已恢復為初始state。注意:被叫function如果您發送價值,則應支付,並且您發送的價值應小於您當前的余額。 調試事務以獲取更多信息。
我的合同:
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
function 並且在用一些以太調用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 {
}
} ```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.