Irys SDK
Irys is currently in alpha testnet. At mainnet launch, all data uploaded to bundlers will be migrated from testnet to mainnet, with no changes to transaction IDs.
Installing (using Ethereum)
Install using npm:
npm install @irys/upload @irys/upload-ethereum
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 & Connecting
The Irys SDK reduces dependency bloat by providing dedicated packages for each token. Your import statements and connection code will differ depending on the token used for payment.
The following code is for using ethereum only, 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
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 a File
const uploadFile = async () => {
const irysUploader = await getIrysUploader();
// Your file
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 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
const uploadFolder = async () => {
const irysUploader = await getIrysUploader();
// Upload an entire folder
const folderToUpload = "./my-images/"; // Path to folder
try {
const receipt = await irysUploader.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 ${receipt.id}`);
} catch (e) {
console.log("Error when uploading ", e);
}
};
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
}
}