-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbot.js
78 lines (65 loc) · 2.27 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const ethers = require("ethers");
const contracts = require("./my_contracts");
const bot = async function () {
const addresses = {
token_in: "0xe9e7cea3dedca5984780bafc599bd69add087d56", //BUSD address
token_out: "", //address of the token you want to buy
factory: "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
router: "0x10ED43C718714eb63d5aA57B78B54704E256024E",
recipient: "", // your public key to be added here
};
const mnemonic = ""; // your mnemonic/private key goes here respect the spacing !
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
let provider = new ethers.providers.JsonRpcProvider(
"https://bsc-dataseed.binance.org/"
);
const account = wallet.connect(provider);
await provider.getBalance(addresses.recipient).then((data) => {
console.log(
ethers.utils.formatEther(data.toString(), { pad: true }) + " BNB"
);
});
const router = new ethers.Contract(
addresses.router,
contracts.routerAdd,
account
);
const BUSD = new ethers.Contract(
addresses.token_in,
contracts.token_in_ABI,
account
);
const howMuchTokentoApprove = ethers.utils.parseUnits("1", "ether");
console.log("Waiting for Approval receipt...");
const txh = await BUSD.approve(addresses.router, howMuchTokentoApprove);
const receipt1 = await txh.wait();
console.log("Transaction receipt"); //uncomment it to approve the router to withdraw busd
//console.log(receipt1);
const amountIn = ethers.utils.parseUnits("1", "ether"); //add the wanted amont of token in to purchase with
const amounts = await router.getAmountsOut(
amountIn,
[addresses.token_in, addresses.token_out],
{
gasLimit: 80000,
gasPrice: ethers.utils.parseUnits("2.0", "gwei"),
}
);
const amountOutMin = amounts[1] - amounts[1] * 0.1; // setting up the slippage here 10% by default
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin, //min amount
[
addresses.token_in, //address of the token in
addresses.token_out, //address of the token out
],
addresses.recipient,
Date.now() + 1000 * 60 * 10,
{
gasLimit: 80000,
gasPrice: ethers.utils.parseUnits("5.0", "gwei"),
}
);
const receipt = await tx.wait();
console.log(receipt);
};
bot();