Is there a way for a Solidity contract to programmatically find out another solidity Contract's address?
Right now I'm letting
Contract A know about
Contract B by hard-coding the address of
B into the constructor of
A, like so:
BContract = MyNFT721(0xA8978c16E9640508947A93B4Df5b49c8740B752D);
But every time I make edits/updates to
B I have to redeploy it, which means it gets a new address - and then
A can no longer find it.
It'd be great if
A could programmatically find the newly updated address of
B, cause right now I have to deploy them separately, deploying
B first, then getting its new Address, then hard-coding this new address into
A, and then redeploying
Its kinda crazy.
(same thing for the ABI's by the way: every time I do an update, I have to copy-paste the new ABI into the calling contract's code...)
I resorted to using the Migrations approach - but from past experience I wouldn't recommend it for deploying to the mainnet. I just remember it kept error'ing out. I think it had to do with how long it was taking for Blocks to be approved/mined.
Remember that Contract 1 has to be deployed first, at which point its address becomes known and available - and can then be passed into Contract 2, which is the next contract in the Migration files cue to be deployed.
So they're basically chained to one another.
But if the first deployment times out - or anything else goes wrong or "too long" with it, the 2nd. deployment will suffer/fail.
So while this solution works well for development - meaning deploying contracts locally to Ganache, it has NOT worked for me on live MainNet deployment.
But I supposed that when you get to that last "MainNet" stage (or even
Rinkeby) - after thoroughly testing everything out locally, you can then just do your deployment manually, one contract at a time - and be good to go.