发送给调用者自己,表示将该合约中的自己应有的以太坊退款到发送者自己的账户
address.transfer(amount)
转账一定数量(以wei为单位)的以太币到指定的地址,遇到任何错误都将抛出异常。我们在Faucet例子中使用过这个方法,针对的是msg.sender这个地址,即msg.sender.transfer
精通以太坊8:智能合约与Solidity(2) | 码农家园精通以太坊8:智能合约与Solidity(2)8.1使用Solidity进行编程有关Solidity的完整文档可以在这里访问:https://solidity.readthedocs.io/en/latest。8.2数据…https://www.codenong.com/cs105234539/
如:weth源码
pragma solidity ^0.4.18;contract WETH9 {string public name = "Wrapped Ether";string public symbol = "WETH";uint8public decimals = 18;eventApproval(address indexed src, address indexed guy, uint wad);eventTransfer(address indexed src, address indexed dst, uint wad);eventDeposit(address indexed dst, uint wad);eventWithdrawal(address indexed src, uint wad);mapping (address => uint) publicbalanceOf;mapping (address => mapping (address => uint))publicallowance;function() public payable {deposit();}function deposit() public payable {balanceOf[msg.sender] += msg.value;Deposit(msg.sender, msg.value);}function withdraw(uint wad) public {require(balanceOf[msg.sender] >= wad);balanceOf[msg.sender] -= wad;msg.sender.transfer(wad);Withdrawal(msg.sender, wad);}function totalSupply() public view returns (uint) {return this.balance;}function approve(address guy, uint wad) public returns (bool) {allowance[msg.sender][guy] = wad;Approval(msg.sender, guy, wad);return true;}function transfer(address dst, uint wad) public returns (bool) {return transferFrom(msg.sender, dst, wad);}function transferFrom(address src, address dst, uint wad)publicreturns (bool){require(balanceOf[src] >= wad);if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {require(allowance[src][msg.sender] >= wad);allowance[src][msg.sender] -= wad;}balanceOf[src] -= wad;balanceOf[dst] += wad;Transfer(src, dst, wad);return true;}}