1

I am using an openZepplin crowdsale contract which has the following constructor

contract myContract is Crowdsale {
    function myContract 
    (
        uint256 _rate,
        address _wallet,
        MintableToken _token
    )
        public
        Crowdsale(_rate, _wallet, _token)
}

I want to make my "_wallet" address the same as the "myContract" address. Is there a way to get the current contract address within the contract?

Sudo code would be something alongs these lines:

contract myContract is Crowdsale {
    function myContract 
    (
        uint256 _rate,
        address _wallet,
        MintableToken _token
    )
        public
        Crowdsale(_rate, <<this.address>>, _token)
}
1

You can try to pass this ir address(this) (which is the same) but it won't work. It seems it thinks you are trying to deploy an abstract contract. As for why, I don't know yet and I am looking into it.

This is what you are basically trying to do. As I said, it won't work.

contract A {
    address public my_address;

    function A(address _val) {
        my_address= _val;
    }
}

contract B is A {
    function B() {
        A(this);
    }
} 

To make it work, you will have to modify your contracts and do the following :

contract A {
    address public my_address;

    function A() {
        my_address= this;
    }
}

contract B is A {
    function B() {
      //do more stuff
    }
} 

If you deploy it on Remix, you will see that my_address will have the correct value.

  • Yes. Exactly, your first example is where is spent a good chunk of my day today. Thanks for the advice, this is very helpful, I will attempt to use this approach – Test1 Test2 Apr 3 '18 at 22:13
  • Alternatively. Since B inherits from A, my_address is available in B. So I can just rewrite it there in "function B". Its pretty hacky, but it will prevent me from changing the OpenZepplin code. – Test1 Test2 Apr 3 '18 at 23:28

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.