Bridge Batch Requests

You can utilize MiniBridge API to make batch bridge requests on multiple wallets. It helps to bridge hundreds of wallets between MiniBridge-supported blockchains within seconds. To move forward, please get familiar with MiniBridge API Docs first. In this tutorial, we will be using Web3.js to manage wallets and interact with the blockchain. Please take it as a reference and feel free to use your desired SDK such as ether.js, alchemy.js, etc.

Prepare the Main Wallet

The first step is to prepare a main wallet which will be used to distribute funds to multiple sub-wallets to make bridge requests.

import Web3 from 'web3';
const mainPrivateKey = 'Your Main Wallet Private Key';
const mainAccount = web3.eth.accounts.privateKeyToAccount(mainPrivateKey);

Distribute ETH

The next step is to write a function to distribute ETH from the main wallet to a bunch of sub-wallets which you would like to do a batch bridge.

async function distributes(fromAddress: string, privateKey: string, toAddress: string, amount: number) {
  const tx = {
    from: fromAddress,
    to: toAddress,
    value: web3.utils.toWei(amount.toString(), 'ether'),
    gas: 21000,
  };

  const signedTx = await web3.eth.accounts.signTransaction(tx, privateKey);
  return web3.eth.sendSignedTransaction(signedTx.rawTransaction!);
}

Then make the ETH distribution in a loop and document all the sub-wallets info into accounts.txt for later use.

while (true) {
    try {
      const account = web3.eth.accounts.create();
      const mainACcount = web3.eth.accounts.privateKeyToAccount(mainPrivateKey)
      await transferBNB(mainAccount.address, mainAccount.privateKey, account.address, 0.002);
      fs.appendFileSync('accounts.txt', `${account.address}, ${account.privateKey}\n`);
      //TODO: Make bridge request via Mini Bridge
      
    } catch (error) {
      console.error('Error occurred:', error);
    }
}

Make Bridge Request

Now we have a bunch of wallets with ETH inside, it's time to fill the gap in the while loop to make the real bridge request.

  1. Confirm your bridge request source chain and destination chain, namely from_id and to_id

  2. Query Mini Bridge config file: https://minibridge-conf.chaineye.tools/conf.json Find the fee amount according to from_id and to_id

  3. In the source chain, transfer ETH to the Mini Bridge address 0x00000000000007736e2F9aA5630B8c812E1F3fc9 with the transfer value set to expected receive amount + fee amount + 8000 + destination chain interalId. For example, if you want to bridge from Arbitrum to Linea and receive 0.01 ETH on Linea, you should set the transfer value to: 0.01*10**18 + 0.00045*10**18 + 8000 + 4 = 10450000000008004

const MiniBridgeAddress = "0x00000000000007736e2F9aA5630B8c812E1F3fc9";
const bridge = async(account, amount, fee, to_id) => {
    const bridgeValue = amount * 10 ** 18 + fee * 10 ** 18 + 8000 + to_id;
    const tx = {
        from: account.address,
        to: MiniBridgeAddress,
        value: bridgeValue,
        gas: 1000000,
    };
    const signedTx = await web3.eth.accounts.signTransaction(tx, account.privateKey);
    const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction!);
    return receipt;
}

Check Bridge Request Status

This step is optional. Usually, the bridge request is fulfilled within 1 minute. You can check your destination chain balance to confirm the bridge request status. Alternatively, you can also use this API to query the status of your bridge requests per wallet:

https://minibridge-conf.chaineye.tools/0x1e0bee6dba877b97e7320d8d6a5757d5a17e1c44.json

Replace the address with your address from the previous step, and make sure to use a lowercase address.

Last updated