Usage with Bundlr

Values too large? Meet Bundlr.

Currently Warp Contracts only support transactions that are below 2KB in size; however you can put arbitrarily large values with the following trick:

  • upload the large value to Bundlr network

  • retrieve the transaction id for that value

  • put the transaction id in the key-value storage

To retrieve the value, simply get the transaction id from the storage and read the value from Arweave with:

const response = await fetch(`https://arweave.net/${transactionId}`);

In other words, you will store key, valueTxId instead of key, value!

This will enable you to store arbitrarily large amounts of data, and retrieve them with respect to their transaction ids, also while reducing the overall size of the contract cache. Albeit, it comes with the cost of paying fees for Bundlr.

You can refer to the code below as an example of uploading a value to Bundlr network.

const Bundlr = require('@bundlr-network/client');

async function upload(jwk, largeValue) {
  const bundlr = new Bundlr.default('http://node1.bundlr.network', 'arweave', jwk);
  const tags = [{name: 'Content-Type', value: 'application/json'}];
  const transaction = await bundlr.createTransaction(
    JSON.stringify({
      data: largeValue,
    }),
    {
      tags: tags,
    }
  );

  await transaction.sign();
  const txID = transaction.id;

  // you can choose to not await this if you want to upload in the background
  // but if the upload fails, you will not be able to get the data from the txid
  await transaction.upload();

  return txID;
}

Last updated