Deploying a contract on different chain with the same addresses

can we deploy a contract even when it has a different values on some values?
for example
uniswap router on eth is : 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D


Pancakeswap router on BSC is : 0x10ED43C718714eb63d5aA57B78B54704E256024E

we need to change the values over the routers on respective chains, if its possible, how so?
What should we use?

One option would be to pass these values as input arguments in the contract's constructor.

For example:

address private immutable _router;

constructor(address router) {
    _router = router;
1 Like

oh my, I did not think of that. nice solution. but would the bytes/memory be affected by those inputs?

Your question is not clear.

The contract byte-code will obviously become slightly larger, since it will now consist also of construction arguments, whose values will be appended to (added at the end of) the byte-code.

But other than this rather minor impact, there shouldn't be any runtime difference.

BTW (and FYI), there is almost never a good reason to hard-code in your contract source code the address of another contract, because you'd typically want to test your contract's interaction with a mockup of that other contract before deploying it to interact with the real one, and forging the mockup to be deployed at the exact same address as the real one is not so easily doable.

thanks for the clear and detailed explanation over what I'm asking.
will be testing the constructor and your suggestion

1 Like

Answer :
you can use CREATE2 or;

you can just make a new fresh wallet with 0 transactions(other than receiving eth for gas of course)
and deploy the contract on different chains

note : contract must be identical, you may want to put the router or other addresses as constructor input.

thanks to @barakman for clarifying the technicalities.

@Crypto_Kid, I've described a tool that you can use in this thread: Using keyless deployment and CREATE3 to deploy contracts to same address on multiple blockchains