DEVELOPER DOCS
SDK

SDK

Implement permanent decentralized storage and Proof of Provenance with just a few lines of code.

Install The SDK

Install using npm

npm install @bundlr-network/client

or yarn

yarn add @bundlr-network/client

Connect To And Fund A node

Connect to any of our three nodes, using a serialized JWK file when using an Arweave wallet

import Bundlr from "@bundlr-network/client";
import fs from "fs";
 
// Load the JWK wallet key file from disk
const privateKey = JSON.parse(fs.readFileSync("walletFile.txt").toString());
 
// Initailze the bundlr SDK
const bundlr = new Bundlr("http://node1.bundlr.network", "arweave", privateKey);
 
// Fund 1 AR
const amountToFund = 1;
// Convert to atomic units
const fundAmountAtomic = bundlr.utils.toAtomic(amountToFund);
// Fund the node
const fundTx = await bundlr.fund(fundAmountAtomic);

Or a private key when using an EVM or Solana wallet

import Bundlr from "@bundlr-network/client";
 
// Your EVM or Solana wallet private key
const privateKey = "6d779d4...";
 
// Initailze the bundlr SDK
const bundlr = new Bundlr("http://node1.bundlr.network", "matic", privateKey);
 
// Fund 0.5 MATIC
const amountToFund = 0.5;
// Convert to atomic units
const fundAmountAtomic = bundlr.utils.toAtomic(amountToFund);
// Fund the node
const fundTx = await bundlr.fund(fundAmountAtomic);

Upload A String

You can opt to either receive a transaction id and timestamp

// Upload data
const dataToUpload = "GM world.";
try {
	const response = await bundlr.upload(dataToUpload);
	console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
} catch (e) {
	console.log("Error uploading file ", e);
}

or a cryptographically signed receipt.

// Upload data
const dataToUpload = "GM world.";
try {
	const receipt = await bundlr.upload(dataToUpload);
	console.log(`Data uploaded ==> https://arweave.net/${receipt.id}`);
} catch (e) {
	console.log("Error uploading file ", e);
}

Upload A File

// Your file
const fileToUpload = "./myImage.png";
 
// Add a custom tag that tells the gateway how to serve this file to a browser
const tags = [{ name: "Content-Type", value: "image/png" }];
 
try {
	const response = await bundlr.uploadFile(fileToUpload, tags);
	console.log(`File uploaded ==> https://arweave.net/${response.id}`);
} catch (e) {
	console.log("Error uploading file ", e);
}

Upload A Folder

When uploading a folder, files can be accessed either directly at https://arweave.net/[transaction-id] or https://arweave.net/[manifest-id]/[file-name]

// Upload an entire folder
const folderToUpload = "./myFolder/"; // PATH TO FOLDER
try {
	const response = await bundlr.uploadFolder("./" + folderToUpload, {
		indexFile: "", // optional index file (file the user will load when accessing the manifest)
		batchSize: 50, //number of items to upload at once
		keepDeleted: false, // whether to keep now deleted items from previous uploads
	}); //returns the manifest ID
 
	console.log(`Files uploaded. Manifest Id ${response.id}`);
} catch (e) {
	console.log("Error uploading file ", e);
}