Solidity
如何將wei從合約轉移到特定地址?
我正在製作一個拍賣系統,我想確保當有人出價更高時,契約會將錢退回到先前出價的地址。
pragma solidity >=0.4.22 <0.6.0; contract simpleAuction{ uint currentValue = 0; address buyer; function set() public payable{ uint sent = msg.value; require(sent>currentValue, "Bid less than current value."); buyer.transfer(currentValue); currentValue = sent; buyer = msg.sender; } function winner() public view returns (address addressWinner, uint newValue){ addressWinner = buyer; newValue = currentValue; } }
錯誤出現
buyer.transfer (currentValue);
在transfer()
僅適用於msg.sender
.
如果您使用的是 Solidity 0.5.0 或更高版本,則需要創建
buyer
一個payable
地址。您可以通過添加payable
到buyer
聲明來做到這一點:
address payable buyer;