1

Is this the right way to get the address of a Contract, that is stored inside another contract:

Example:

import "B.sol";
contract A{
    B private bContract;
    construtor(){}

    function setBContract(address _address) {
        bContract = new B(_address);
    }

    function getBAddress() returns(address){
        return address(bContract);
    }

}

Or do I have to save the address in some variable like so:

function setBContract(address _address) {
    bContract = new B(_address);
    bAddress = _address;
}

And then just retrieve it over the bAddress variable? Or is it exactly the same?

And which one ist the preffered way? (gas wise). I assume storing another value will cost more?

1
  • 1
    The first one, less gas as u said
    – Majd TL
    Apr 17, 2021 at 11:05

0

Your Answer

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

Browse other questions tagged or ask your own question.