发送给调用者自己,表示将该合约中的自己应有的以太坊退款到发送者自己的账户
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/文章来源:https://www.toymoban.com/news/detail-515553.html
如:weth源码文章来源地址https://www.toymoban.com/news/detail-515553.html
pragma solidity ^0.4.18;
contract WETH9 {
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;
event Approval(address indexed src, address indexed guy, uint wad);
event Transfer(address indexed src, address indexed dst, uint wad);
event Deposit(address indexed dst, uint wad);
event Withdrawal(address indexed src, uint wad);
mapping (address => uint) public balanceOf;
mapping (address => mapping (address => uint)) public allowance;
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)
public
returns (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;
}
}
到了这里,关于solidity msg.sender.transfer发送给谁的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!