-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflashbots-script.js
More file actions
55 lines (44 loc) · 1.73 KB
/
flashbots-script.js
File metadata and controls
55 lines (44 loc) · 1.73 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
const { Wallet, providers, utils } = require("ethers");
const { FlashbotsBundleProvider, FlashbotsBundleResolution } = require("@flashbots/ethers-provider-bundle");
const { exit } = require("process");
const main = async () => {
if (
process.env.FUNDING_KEY === undefined ||
process.env.VICTIM_KEY === undefined ||
process.env.DESTINATION_ADDRESS === undefined
) {
console.error("Please set FUNDING_KEY, VICTIM_KEY, and DESTINATION_ADDRESS env");
exit(1);
}
const provider = new providers.JsonRpcProvider("https://rpc.goerli.mudit.blog/");
// Input your recovery phrase (seed phrase) for the funding wallet here
const fundingRecoveryPhrase = process.env.FUNDING_KEY; // Use the environment variable
// Generate a wallet using the recovery phrase
const fundingWallet = Wallet.fromMnemonic(fundingRecoveryPhrase);
// Set up the Flashbots provider
const flashbotsProvider = await FlashbotsBundleProvider.create(provider, fundingWallet);
// You can now use the flashbotsProvider to send bundles to Flashbots
// Example: Send a bundle
const bundle = [
{
transaction: {
to: process.env.DESTINATION_ADDRESS, // Use the destination address
value: utils.parseEther("0.1"), // Amount in Ether
gasPrice: utils.parseUnits("20", "gwei"),
},
signer: fundingWallet,
},
];
try {
const bundleResponse = await flashbotsProvider.sendBundle(bundle);
if (bundleResponse === FlashbotsBundleResolution.BundleIncluded) {
console.log("Bundle was included in a block!");
} else {
console.log("Bundle was not included in a block.");
}
} catch (error) {
console.error("Error sending bundle:", error);
}
// Continue with more script logic...
};
main();