-
Notifications
You must be signed in to change notification settings - Fork 75
/
earlybuy.js
95 lines (76 loc) · 2.6 KB
/
earlybuy.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
DWYOR
-no slip
-buying new tokens
-buying with BNB
original script by eattheblocks
npm install ethers
npm install fs
node earlybuy.js
*/
const ethers = require('ethers');
const fs = require('fs');
const addresses = {
WBNB: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
factory: '0xca143ce32fe78f1f7019d7d551a6402fc5350c73',
router: '0x10ed43c718714eb63d5aa57b78b54704e256024e',
recipient: 'YOUR ADDRESS'
};
const amountIn = ethers.utils.parseUnits('0.001', 'ether'); //buying amount 0.001 BNB
const mnemonic = 'YOUR PRIVATE KEY';
const provider = new ethers.providers.WebSocketProvider('YOUR WSS URL');
const wallet = new ethers.Wallet(mnemonic);
const account = wallet.connect(provider);
const factory = new ethers.Contract(
addresses.factory,
[
'event PairCreated(address indexed token0, address indexed token1, address pair, uint)',
'function getPair(address tokenA, address tokenB) external view returns (address pair)'
],
account
);
const router = new ethers.Contract(
addresses.router,
[
'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)',
'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)',
'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)',
'function swapExactTokensForETHSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] path, address to, uint256 deadline) external returns (uint[] memory amounts)'
],
account
);
console.log('BOT STARTED - Semoga opit');
factory.on('PairCreated', async (token0, token1, pairAddress) => {
let tokenIn, tokenOut;
if(token0 === addresses.WBNB) {
tokenIn = token0;
tokenOut = token1;
}
if(token1 == addresses.WBNB) {
tokenIn = token1;
tokenOut = token0;
}
if(typeof tokenIn === 'undefined') {
return;
}
try {
fs.appendFileSync("data.csv",'\n' + [tokenOut,pairAddress].join(","));
const tx = await router.swapExactETHForTokens(
amountIn,
[tokenIn, tokenOut],
addresses.recipient,
Date.now() + 1000 * 60 * 10, //10m,
{
'gasLimit': 300000,
'gasPrice': ethers.utils.parseUnits('5.102', 'gwei'),
'value': amountIn
}
);
const receipt = await tx.wait();
console.log(`tx: https://www.bscscan.com/tx/${receipt.logs[1].transactionHash}`);
console.log('next');
// process.exit(); // Remove slash to stop buying new tokens
} catch(error) {
//console.log(error);
}
});