18

I am having a problem with my smart contract making value transfers. My current environment:

Truffle v5.0.0-beta.2 (core: 5.0.0-beta.2)
Solidity v0.5.0 (solc-js)
Node v8.11.1

I created the following test function to help track down the problem:

pragma solidity ^0.4.24;

import "../node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol";
import "../node_modules/openzeppelin-solidity/contracts/lifecycle/Pausable.sol";

contract EtherBandBattlesManager is Pausable {

using SafeMath for uint256;    

    function testPayment(address _payeeAddr)
            payable
            public
            onlyOwner
            {
        require(_payeeAddr != address(0), "(testPayment) The payee address is not set.");
        require(msg.value != 0, "(testPayment) The amount of value accompanying the transaction is zero.");

        // Make the payment.
        _payeeAddr.transfer(msg.value);
    }
}

Before I upgraded to Truffle 5 beta the contract compiled successfully. But when I made a call to testPayment() I did see the balance of the Ganache account I was paying from decrease, but I did not see the balance of the destination account increase.

I then upgraded to Truffle 5.0 beta.

Now I get a fatal compiler error saying:

/ether-band-battles-work/solidity/contracts/EtherBandBattlesManager.sol:1142:9: TypeError: Member "transfer" not found or not visible after argument-dependent lookup in address.
    _payeeAddr.transfer(pendingPaymentDetails.paymentAmountGwei);

My understanding is that the transfer() function was introduced in Solidity 4.1 and I am using 4.24 as you can see. Why can't the compiler find the transfer() function? Also, any comments on why I am not seeing the balance on the destination account go up after making the transfer() call would be appreciated.

1 Answer 1

27

This is due to some breaking changes in Solidity version 0.5. Namely that an address has to be marked as payable - otherwise it won't have the transfer function. More info here: https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html#explicitness-requirements

So just change you function parameters from address _payeeAddr to address payable _payeeAddr and it will work just fine.

3
  • Thanks. Any ideas about the payment not increasing the destination balance? Also, so what do you do with an address you get back from ecrecover(), which is not "address payable" that you would like to pay? Commented Nov 26, 2018 at 20:26
  • 1
    99% of the time when some balance is not increased (at least in my experience) even if all addresses are correct, it's due to not being properly synchronized with the blockchain. And about second point, directly from the link I posted: "Converting address to address payable is possible via conversion through uint160" Commented Nov 27, 2018 at 3:58
  • 1
    1) "it's due to not being properly synchronized with the blockchain": even on Ganache? I reloaded Ganache multiple times and still have the problem. I'm starting to wonder if it's how I pass addresses to the smart contract to be paid. 2) A uint160 cast to convert to address payable? Wow, I never would have thought of that! Commented Nov 27, 2018 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.