Irys SDK

Installing

This example uses ETH for payment. You can use any of the supported tokens.

Install using npm:

npm install @irys/upload @irys/upload-ethereum

Connecting to the network

The following code is for using ETH for payment, we also have examples covering all supported tokens.

import { Uploader } from "@irys/upload";
import { Ethereum } from "@irys/upload-ethereum";

const getIrysUploader = async () => {
  const irysUploader = await Uploader(Ethereum).withWallet(process.env.PRIVATE_KEY);
  return irysUploader;
};

Funding Irys

Fund your account on the Irys network using any of our supported tokens:

const fundAccount = async () => {
	const irysUploader = await getIrysUploader();
	try {
		const fundTx = await irysUploader.fund(irysUploader.utils.toAtomic(0.05));
		console.log(`Successfully funded ${irysUploader.utils.fromAtomic(fundTx.quantity)} ${irysUploader.token}`);
	} catch (e) {
		console.log("Error when funding ", e);
	}
};

Uploading

Uploading Data

Uploading a File

Uploading a Folder

You can upload a group of files as a single transaction from both the server and the browser.

ℹ️ When uploading a folder, files can be accessed either directly at https://gateway.irys.xyz/:transactionId or https://gateway.irys.xyz/:manifestId/:fileName

3rd-Party Build Tools

Parcel

If using Parcel, you will need to manually enable package exports by adding the following to the package.json file in your project root directory.

Last updated