Skip to content

Instantly share code, notes, and snippets.

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 roshanr95/b9cef0ab9f923a2b4b0144fe8a0fb978 to your computer and use it in GitHub Desktop.
Save roshanr95/b9cef0ab9f923a2b4b0144fe8a0fb978 to your computer and use it in GitHub Desktop.
import { ethers, providers, Wallet } from "ethers";
import { FlashbotsBundleProvider } from "@flashbots/ethers-provider-bundle";
import axios from 'axios';
async function fetchProof(address) {
let resp = await axios({
method: 'get',
url: 'https://api.otherside.xyz/proofs/'+address,
});
return resp.data;
}
async function main() {
let base = new ethers.providers.JsonRpcProvider({url: "http://127.0.0.1:8545/"})
await base.ready
let basews = new ethers.providers.WebSocketProvider("ws://127.0.0.1:8546/")
console.log(await basews.getNetwork())
const user = new ethers.Wallet('...key...', base);
let provider = new FlashbotsBundleProvider(base, user, {url: 'https://relay.flashbots.net/'});
const accounts = [
new ethers.Wallet('...key...', base),
];
const proofs = await Promise.all(accounts.map(x => fetchProof(x.address)));
console.log(proofs);
const CONTRACT_ADDRESS = "0x34d85c9CDeB23FA97cb08333b511ac86E1C4E258"
const ABI = ["function mintLands(uint256,bytes32[])"]
const contracts = accounts.map(x => new ethers.Contract(CONTRACT_ADDRESS, ABI, x))
const txs = [
{
signer: accounts[0],
transaction: await contracts[0].populateTransaction.mintLands(2, proofs[0], {
gasPrice: "200000000000",
gasLimit: "500000",
})
},
];
basews.on('pending', async (tx) => {
let trans = await basews.getTransaction(tx)
if(!trans) return;
if(trans.to !== "0x34d85c9CDeB23FA97cb08333b511ac86E1C4E258") return;
if(trans.from.toLowerCase() !== "0xcda9742761cb069ff70b5cd5fcb8dd636a453961") return;
console.log(trans)
if(trans.data.substr(0, 10) !== "0x848d075e") return;
console.log(trans)
let alltxs = [
{
signedTransaction: ethers.utils.serializeTransaction(trans, {v: trans.v, r: trans.r, s: trans.s}),
},
txs[0],
];
const blk = await base.getBlockNumber()
const result = await provider.sendBundle(alltxs, blk + 1);
console.log(result)
})
}
main().catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment