1

So I'm learning Solidity in creating a new token. I successfully created a token and implemented custom tax and burn functionalities. Now I'm trying to understand the Uniswap liquidity features. The thing I don't understand is the address(this) function. In many example code's I see liquidity being added FROM this address and the pair tokens are stored there aswell.

However, how do I access this address through metamask? How are the tokens stored there? Does a simple contract where totalSupply is transferd to owner() or (msg.sender) also have tokens in address(this)? Address(this) totally confuses my mind.

So this piece of code:

uniswapV2Router.addLiquidityETH{value: ethAmount}(
        address(this), //What is this address, shouldn't this be the owner address?
        tokenAmount, //Custom token amount
        0, // slippage is unavoidable
        0, // slippage is unavoidable
        address(this), //Liquidity tokens are stored here and are inaccesible?
        block.timestamp 
    );

So in this code example above. The first parameter and the second last parameter is address(token). The first parameter should be according to the docs "The contract address of the desired token." Which is my own token of course. Now the second param is the amount of this token. How does address(this) contain tokens to add to the liq pool? The second last param is according the docs "Recipient of the liquidity tokens.", are they inaccessible?

2 Answers 2

1

The

address(this)

is the address of the deployed smart contract itself.

In Uniswap context, guessing without you quoting any source code, it is the address of the pair contract.

0
0
address(this)

refers to the contract address you're working on in which you're writing code.

In this case, Both of the addresses should not be using address(this), because the two address parameters in the .addLiquidityETH are address token & address to which means you're transferring your tokens back to this contract. to is the recipient of the liquidity tokens

This function will create or add liquidity to a token/weth pool.

  1. One address should be the token address of the pool
  2. second address should be the recipient address

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.