Proper way of automating trades on uniswap with nodejs
Proper way of automating trades on uniswap with nodejs
Loading saved threads...
BitQueen · External communityPost link
External question — Ethereum Stack Exchange
Author: BitQueen
Original post: https://ethereum.stackexchange.com/questions/117558
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I am wondering what would be the proper way (if possible at all) to automate trades on uniswap using their SDK or just web3 or ethers with the router and factory contract instances.
I want to build a small script, that takes a Token as an input and automatically buys that on uniswap. For example, I call the script with"XLM" it should buy XLM against a Stable coin I predefine.
Now in order to make trades from code as far as I know, I always have to create the contract instances and everything. But as I dont know what Token to trade in advance, I can not have all token contracts and objects required generated before I even trade.
Does anyone have experience with what I am trying to do and can guide me the way or give some directions? I am not looking for a finished example, just want toget some idea.
Quote
Report
gazoblock · External communityPost link
External answer — Ethereum Stack Exchange
Author: gazoblock
Original post: https://ethereum.stackexchange.com/a/117563
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Uniswap - like dex`s have similar Router interface, where you can find function
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
You can interact with this function to make transfers under your code, like that:
const StableToken = "0xc02...c756cc2"
const RequieredToken = "0x6b1...5271d0f"
const routerContract = new web3.eth.Contract(
UniswapRouterABI,
"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
);
routerContract.methods.swapExactTokensForTokens(
1e6, // you provide 1 USDT with 6 decimals
0, //you expect to receive any amount of RequieredToken
[StableToken,RequieredToken],// tokenIn => tokenOut, minimum 2
myWalletAddress, //RequieredToken receiver (you)
deadline // number that represents blockNumber. If you tx executes after this block - tx will be reverted. You can place there current block number + 1000
)
.send(from: myWalletAddress)
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Ethereum Stack Exchange Author: BitQueen Source score (net votes, not local likes): 0 Original post: https://ethereum.stackexchange.com/questions/117558 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I am wondering what would be the proper way (if possible at all) to automate trades on uniswap using their SDK or just web3 or ethers with the router and factory contract instances. I want to build a small script, that takes a Token as an input and automatically buys that on uniswap. For example, I call the script with"XLM" it should buy XLM against a Stable coin I predefine. Now in order to make trades from code as far as I know, I always have to create the contract instances and everything. But as I dont know what Token to trade in advance, I can not have all token contracts and objects required generated before I even trade. Does anyone have experience with what I am trying to do and can guide me the way or give some directions? I am not looking for a finished example, just want toget some idea.
Checking account access…