0

There seem to be at least two ways of setting the address of an external contract:

  • At deploy/constructor time: function contractName(address _otherContractAddress)
  • A setter function that can be called once the contract is deployed: function setExternalAddress(address _otherContractAddress)

What are other ways of doing this and/or is there a canonical way of doing so? I am leaning towards the second solution above because it is more flexible post-deploy and the deploy process will be simpler.

1 Answer 1

1

This boils down to 2 things.

Do you need the external contract immediately after your main contract is deployed? Does your contract work without a link to the external contract? And even more important: are you using the external contract in any of the instructions of the constructor? If yes, you'll need to put it in the constructor.

Having a setter is only necessary if you'll ever need to be able to update the reference to the external contract. If you do, add the setter. Don't forget to restrict the setter, so only the owner can change it.

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.