0

I am wondering if it is possible to cast a contract-reference to an address payable (in order to send to it money) or if it is possible to declare a contract-reference directly payable (with solidity > 0.5.0). So that the function transfer can be used.

To make the question more clear, I provide here a minimal example:

contract A {
     function() payable {
          // fallback logic goes here ...
     }
}

contract B {

    constructor() payable public {
        A a = new A();
        address payable receiver = address(a); // cast goes here
        receiver.transfer(msg.value);
     }
}

Concretely, how can I send money to A via transfer?

1

This works.

pragma solidity 0.5.1;

contract A {
     function() external payable {
          // fallback logic goes here ...
     }
}

contract B {

    constructor() payable public {
        A a = new A();
        address payable receiver = address(a); // cast goes here
        receiver.transfer(msg.value);
     }
}

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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