Is there a way to know the address of the smart contract you are writing before deploying it? Or somehow reference the smart contract address in the smart contract?
1 Answer
The contract's address can be is generated based on the account nonce and account's own address: How to deploy smart contract in predefined contract address in private ethereum network? . So you can calculate it in advance.
Or you can reference the contract's own address (whatever it is) in Solidity with address(this)
.
P.S. New opcode CREATE2
enables even more flexibility in knowing contract addresses in advance (but it's rather complicated): https://hackernoon.com/using-ethereums-create2-nw2137q7