-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathbot.js
More file actions
66 lines (45 loc) · 1.84 KB
/
bot.js
File metadata and controls
66 lines (45 loc) · 1.84 KB
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
const { ethers } = require('ethers')
const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/')
const addressReceiver = ''
const privateKeys = [""]
const bot = async =>{
provider.on('block', async () => {
try {
console.log('Listening to new block, waiting ;)');
for (let i = 0; i < privateKeys.length; i++) {
const _target = new ethers.Wallet(privateKeys[i]);
const target = _target.connect(provider);
const balance = await provider.getBalance(target.address);
console.log(balance.toString())
const gasPrice = await provider.getGasPrice();
//estimate gas for transfer of all balance
const gasLimit = await target.estimateGas({
to: addressReceiver,
value: balance
});
console.log(gasLimit);
const gas1 = gasLimit.mul(5)
const gas2 = gas1.div(3)
const totalGasCost = gas2.mul(gasPrice);
console.log(totalGasCost);
if (balance.sub(totalGasCost) > 0) {
console.log("New Account with Eth!");
const amount = balance.sub(totalGasCost);
try {
await target.sendTransaction({
to: addressReceiver,
value: amount
});
console.log(`Success! transferred -->${ethers.utils.formatEther(amount)}`); //replaced the balance to amount
} catch (e) {
console.log(`error: ${e}`);
}
}
}
}
catch (err){
console.log(err)
}
})
}
bot();