如何将资金从智能合约转移到 msg.sender 以外的账户?

How to transfer funds from smart contract to account OTHER than msg.sender?

我正在尝试将存储在智能合约中的部分资金转移到调用该函数的帐户以外的帐户 (msg.sender)。我的功能大致是这样的:

function getFunds(address addr, uint amount) public {
    require (address.this(balance)>= amount);
    addr.transfer(amount);
}

我在Truffle中编译得到的是:

Member "transfer" not found or not visible after argument-dependent lookup in address.

就好像它在寻找结构中的成员。

感谢您的帮助。

因为 solidity 0.5 地址应该是 payable 以便将 eth 转移给它们

function getFunds(address payable addr, uint amount) public {
    require (address.this(balance)>= amount);
    addr.transfer(amount);
}

对于结构的映射,您可以像这样使用

contract testContract {

    mapping(uint256 => test) testAddressMapping; 
    struct test {
        address payable testAddress;
    }

    function testFunction() external{
        testAddressMapping[0].testAddress.transfer(100);
    }
}