Onchain Storage
Quickstart
Get started with the Irys SDK. Install, connect, fund, and upload data to Irys in minutes.
Installing
Install using npm. This example uses ETH for payment. You can use any of the supported tokens.
npm install @irys/upload @irys/upload-ethereumConnecting to the Network
Connect to the Irys network using a private key and the Ethereum token. By default, the SDK uploads through the Irys L1 bundler — see Bundlers for the full list of bundler endpoints and where each one seeds data.
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 Your Account
Fund your account on the Irys network using any of the 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 Data
Upload raw data directly to Irys:
const uploadData = async () => {
const irysUploader = await getIrysUploader();
const dataToUpload = "hirys world.";
try {
const receipt = await irysUploader.upload(dataToUpload);
console.log(`Data uploaded ==> https://gateway.irys.xyz/${receipt.id}`);
} catch (e) {
console.log("Error when uploading ", e);
}
};Uploading Files
Upload individual files with optional metadata tags:
const uploadFile = async () => {
const irysUploader = await getIrysUploader();
const fileToUpload = "./myImage.png";
const tags = [{ name: "application-id", value: "MyNFTDrop" }];
try {
const receipt = await irysUploader.uploadFile(fileToUpload, { tags: tags });
console.log(`File uploaded ==> https://gateway.irys.xyz/${receipt.id}`);
} catch (e) {
console.log("Error when uploading ", e);
}
};Uploading Folders
You can upload a group of files as a single transaction from both the server and the browser.
const uploadFolder = async () => {
const irysUploader = await getIrysUploader();
const folderToUpload = "./my-images/";
try {
const receipt = await irysUploader.uploadFolder("./" + folderToUpload, {
indexFile: "",
batchSize: 50,
keepDeleted: false,
});
console.log(`Files uploaded. Manifest ID ${receipt.id}`);
} catch (e) {
console.log("Error when uploading ", e);
}
};https://gateway.irys.xyz/:transactionId or via the manifest at https://gateway.irys.xyz/:manifestId/:fileName.Build Tools
If you are using Parcel as your build tool, you will need to manually enable package exports by adding the following to the package.json file in your project root directory:
{
"@parcel/resolver-default": {
"packageExports": true
}
}