solidity 之transfer使用常见错误:Member "transfer" not found or not visible after argument-depende

pragma solidity ^0.5.0;

contract Test {
    constructor() public payable{

    }

    function test() public view returns (uint){
        return address(this).balance;
    }

    //这里务必注意, 一个地址要支持转入或转出,必须设置为address payable类型,否则会报错!
    function send(address payable a) public {

        if (address(this).balance > 1e18) {
            // 特别注意:这里a.transfer的意思是:当前合约向地址a发送多少数量的ETH币()
            // 这里的a是接收方,不是发送方!!!
            a.transfer(1e18);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43343144/article/details/88143896