I have an idea for a smart contract where 0.05% of each transaction would be converted to a stable coin from within the smart contract and sent to a separate account. I was planning on having DAI be the coin of choice. Does anyone have any useful tutorials or advice for something like this? I’ve been reading through the UNISWAP Api documentation in the hopes that I might be able to use python to automatically make a trade but I haven’t had luck yet. Any and all advice would be appreciated.
1 Answer
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
swapExactTokensForTokens
allows you to swap your token for USDT, DAI, or whatever.
function swapMyTokenToUSDT(uint amountToken) external {
address[] memory path = new address[](2);
path[0] = USDTAddress;
path[1] = tokenAddress;
uniswapV2Router.swapExactTokensForTokens(
amountToken,
0, // accept any amount of tokens
path,
address(this),//receiver address
block.timestamp
);
}
Here is how the function should be implemented in your smart contract