Sending to Arweave with Bundlr

How is the content of a promise sent to Arweave?

If the option is selected, files are zipped and sent to Arweave using Bundlr - which is a PoS network built on top of Arweave. Bundlr nodes bundle multiple transactions, each time for two minutes, and submit them onto Arweave, which makes the process way faster and cheaper, whilst remaining as reliable (Learn more).

Since the project is deployed on testnets (Polygon Mumbai), the archive is sent to a devnet bundler, which allows the user to pay with testnet currencies.

The only difference with mainnet is that the files are not actually moved to Arweave, but instead deleted after a week.

How are the files sent with Bundlr?

The process is different from the one used to send files to IPFS, and requires more input from the user. It can be condensed into the following steps:

  1. Connect the user wallet to the Bundlr node.

  2. Prepare the upload

    1. Create the zip archive

    2. Find the price in MATIC for n amount of data.

    3. Fund the Bundlr "wallet" - the address associated to the user's private key

  3. Create the transaction and upload the data.

Each stage is outlined below, with details in the relevant code.

Connecting to Bundlr

uploadToArweave.js
const initializeBundlr = async (provider, chainId) => {
  // Find the RPC url based on the chain (mainnet or testnet)
  const rpcUrl =
    chainId === 80001
      ? process.env.NEXT_PUBLIC_MUMBAI_RPC_URL
      : process.env.NEXT_PUBLIC_POLYGON_RPC_URL;
  // Get the appropriate bundler url (mainnet or devnet)
  const bundlrUrl = networkMapping[chainId].Bundlr[0];
  // Connect with MATIC as a currency to the appropriate node
  const bundlr = new WebBundlr(bundlrUrl, 'matic', provider, {
    providerUrl: rpcUrl,
  });

  await bundlr.ready().catch((err) => {
    console.log(err);
    toast.error('Please connect to the Arweave network to continue');
  });

  let isReady;
  if (bundlr.address === 'Please run `await bundlr.ready()`') {
    isReady = false;
  } else {
    isReady = true;
  }

  return { instance: bundlr, isReady };
};

After the user is connected, they can start interacting with the network.

Preparing the transaction

Sending the transaction

Resources

Last updated