Skip to content

Instantly share code, notes, and snippets.

@AshiqAmien
Created August 18, 2023 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshiqAmien/4de77ea4b78a0542370d5cf5388ceb12 to your computer and use it in GitHub Desktop.
Save AshiqAmien/4de77ea4b78a0542370d5cf5388ceb12 to your computer and use it in GitHub Desktop.
MEV-share CTF script
```typescript
import { Wallet, JsonRpcProvider, TransactionRequest, toBigInt, keccak256 } from "ethers"
import MevShareClient, {
IPendingTransaction, IPendingBundle, BundleParams
} from ".."
import Env from './lib/env'
import { Mutex } from "async-mutex"
const provider = new JsonRpcProvider(Env.providerUrl)
const authSigner = new Wallet(Env.authKey, provider)
const mevShareClient = MevShareClient.useEthereumGoerli(authSigner)
const NUM_TARGET_BLOCKS = 25;
async function main() {
mevShareClient.on("transaction", async (tx: IPendingTransaction) => {
if (<CONDITION_HERE>) {
console.log("found tx: " + tx.hash);
const wallet = new Wallet(Env.senderKey).connect(provider);
const feeData = await provider.getFeeData();//stop alchemy from shouting
const unsignedtx: TransactionRequest = {
type: 2,
chainId: provider._network.chainId,
to: "0x20a1A5857fDff817aa1BD8097027a841D4969AA5".toLocaleLowerCase(),
nonce: await wallet.getNonce(),
value: 0,
gasLimit: 400000,
data: "0xb88a802f",
maxFeePerGas: toBigInt(feeData.maxFeePerGas || 42) + BigInt(1e3),
maxPriorityFeePerGas: toBigInt(feeData.maxPriorityFeePerGas || 2) + BigInt(1e3),
};
const bundle = [
{ hash: tx.hash },
{ tx: await wallet.signTransaction(unsignedtx), canRevert: false },
]
const targetBlock = await provider.getBlockNumber() + 1;
const bundleParams: BundleParams = {
inclusion: {
block: targetBlock,
maxBlock: await provider.getBlockNumber() + NUM_TARGET_BLOCKS,
},
body: bundle,
}
const bundleResult = await mevShareClient.sendBundle(bundleParams);
console.log("sending bundle, bundleResult: ", bundleResult)
}
})
}
main();
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment