0

Sometimes when people create a new token they declare a constructor:

constructor () public {
        _rOwned[_msgSender()] = _rTotal;
        
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);
         // Create a uniswap pair for this new token
        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());

What is the purpose of this. Does the router address absolutely has to be included in the constructor. Cannot I create the token then choose a dex later ?

1 Answer 1

1

You absolutely can initialize it later, most of the programmers do it in this way because is a good practice to initialize your resources at the constructor, but it might not be your case. You can initialize whenever is reasonable based in your business logic

2
  • And if I initilize it later it just means adding liquidity to a dex right?
    – qubitz
    Commented Sep 6, 2021 at 17:02
  • Not necessarily, you can initialize it for multiple reasons, being adding liquidity one of them Commented Sep 6, 2021 at 17:22

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.