Q: What's the difference between createPair and addLiquidity? createPair declare in Uniswap Factory contract, addLiquidity declared in Uniswap Router contract, both can create liquidity pair and swap avaliable in app.uniswap.org.
But most developers use addLiquidity instead of createPair. What's the difference between createPair and addLiquidity?

A: As the function naming suggests, both functions have a different purpose.

*

*createPair() is meant to be used mainly for creating a pair

*addLiquidity() is for adding liquidity to a pair

Having said that, addLiquidity() is more robust and performs a call to createPair() if the pair doesn't exist yet. So by calling addLiquidity() you can "create a pair and add liquidity" in one transaction, instead of splitting the action into 2 separate transactions, saving transaction fees.
