A trading tool in the Uniswap using smart-order-router
-
Run
npm installto install dependencies -
Create
.envfile and setPRIVATE_KEYandJSON_RPC_PROVIDER -
Open new terminal run
npx hardhat node --network hardhatto start local network.
Because WETH is used as the local currency by default, you will not be able to trade if you do not have WETH in your account. You can use wrap_eth.ts to convert 100 ETH to WETH.
ts-node wrap_eth.tsFor v2 version(outdated don't use)
Use 1 WETH to exchange for DAI. Currently v2 tokenIn is the default, and the WETH used can be modified later.
The parameter is tokenOut
// outdated don't use
ts-node src/trade_v2.js 0x6B175474E89094C44Da98b954EedeAC495271d0F For v3 version(outdated don't use)
The parameters are tokenIn, tokenOut, amountIn, fee
// outdated don't use
ts-node src/trade_v3.ts 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 0x38e68a37e401f7271568cecaac63c6b1e19130b4 1 1000
0For smart-order-router(recommend)
// ts-node src/route.ts tokenIn tokenOut amountIn
// quote 10000 tokens for WETH
ts-node src/route.ts 0x42bbfa2e77757c645eeaad1655e0911a7553efbc 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 10000 If you want to trade
// ts-node src/route.ts tokenIn tokenOut amountIn trade
// trade 1 WETH for BS
ts-node src/route.ts 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 0x5ECa7B975E34567d9460FA613013A7A6993ad185 1 tradeYou can connect your metamask to your local test network, so that your can see the balance of the tokens
All code has only been tested on the local test network and is for learning purposes only.Use this code to trade at your own risk.

