Irys SDK
Irys is currently in private testnet. At mainnet launch, all uploaded data will be migrated from testnet to mainnet. Transactions IDs will not change.
Installing
Install using npm:
npm install @irys-network/bundler-client
or yarn:
yarn add @irys-network/bundler-client
If you get a warning saying bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
during
install, it can be safely ignored. For details on how make it go away, see our troubleshooting
guide.
Importing
import Irys from "@irys-network/bundler-client";
Connecting to Irys
Connect using a private key linked to an EVM or Solana wallet:
const getIrys = async () => {
const network = "testnet";
// RPC URLs change often, use a recent one from https://chainlist.org/
const providerUrl = "";
const token = "ethereum";
const irys = new Irys({
network,
token, // Token used for payment
key: process.env.PRIVATE_KEY, // ETH or SOL private key
config: { providerUrl }, // Optional provider URL, only required when using Devnet
});
return irys;
};
Provider URLs
Use the providerUrl
parameter to specify an RPC provider, this is required.
When working with Aptos, use "testnet" | "devnet" instead of a URL.
Funding Irys
Fund your account on the Irys network using any of our supported tokens:
const fundNode = async () => {
const irys = await getIrys();
try {
const fundTx = await irys.fund(irys.utils.toAtomic(0.05));
console.log(`Successfully funded ${irys.utils.fromAtomic(fundTx.quantity)} ${irys.token}`);
} catch (e) {
console.log("Error uploading data ", e);
}
};
Uploading
Uploading Data
const uploadData = async () => {
const irys = await getIrys();
const dataToUpload = "hirys world.";
try {
const receipt = await irys.upload(dataToUpload);
console.log(`Data uploaded ==> https://gateway.irys.xyz/${receipt.id}`);
} catch (e) {
console.log("Error uploading data ", e);
}
};
Uploading a File
const uploadFile = async () => {
const irys = await getIrys();
// Your file
const fileToUpload = "./myImage.png";
const tags = [{ name: "application-id", value: "MyNFTDrop" }];
try {
const receipt = await irys.uploadFile(fileToUpload, { tags: tags });
console.log(`File uploaded ==> https://gateway.irys.xyz/${receipt.id}`);
} catch (e) {
console.log("Error uploading file ", e);
}
};
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/[transaction-id]
or https://gateway.irys.xyz/[manifest-id]/[file-name]
Server
const uploadFolder = async () => {
const irys = await getIrys();
// Upload an entire folder
const folderToUpload = "./my-images/"; // Path to folder
try {
const receipt = await irys.uploadFolder("./" + folderToUpload, {
indexFile: "", // Optional index file (file the user will load when accessing the manifest)
batchSize: 50, // Nmber 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 ${receipt.id}`);
} catch (e) {
console.log("Error uploading file ", e);
}
};
Browser
const webIrys = await getWebIrys();
const files: File[] = [];
const tags: { name: string; value: string }[][] = [];
// Convert Files to TaggedFiles
const taggedFiles = files.map((f: TaggedFile, i: number) => {
f.tags = tags[i];
return f;
});
const response = await webIrys.uploadFolder(taggedFiles);
3rd-Party Build Tools
Parcel
If using Parcel (opens in a new tab), you will need to manually enable package exports (opens in a new tab) by adding the following to the package.json
file in your project root directory.
{
"@parcel/resolver-default": {
"packageExports": true
}
}