solidity msg.sender.transfer发送给谁

Posted 软件工程小施同学

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了solidity msg.sender.transfer发送给谁相关的知识,希望对你有一定的参考价值。

发送给调用者自己,表示将该合约中的自己应有的以太坊退款到发送者自己的账户

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";
    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发送给谁的主要内容,如果未能解决你的问题,请参考以下文章

—solidity中的HelloWord

智能合约语言 Solidity 教程系列8 - Solidity API

智能合约语言 Solidity 教程系列8 - Solidity API

solidity二固定长度数组动态长度数组字符串之间的转换solidity字典hash表的使用solidity——memorystorage使用注意项solidity状态变量局部变量

《solidity学习笔记》chapter 1-solidity基础知识

Solidity 学习