I want to write a code to put liquidity on uniswap liquidity pool, but I haven't found any toturial or example code related to this. Additionally, I found a python library to interact with uniswap named python-uniswap, it has some methods related to liquidity pools but as it doesn't have a complete example, I get confused and don't know how to use that.
Can anybody help me with python-uniswap? Or does anybody know another way to interact with uniswap pools using web3 ?
Best Answer
You can use web3py to interact with function addLiquidity in Uniswap. Here is an example.
Let assume you want to add liquidity of token A with ETH in Uniswap. Thus, the Uniswap function that you want to execute is addLiquidityETH. That function take the following input and their related definition:
Then, if you've already knew the input. You can use web3py for adding the LP as shown below.:
Then you should be able to add liquidity successfully using web3py. Here is the transaction hash that I used the previous code to test in BSC testnet: https://testnet.bscscan.com/tx/0x29ca08347d40bdfe20cc685f85ec5183364414ff66e7fdc1f94c5db00fd9819f
Hope it helps you!!!