Build
ONCHAIN STORAGE
SDK
Data Mode

Data Mode

The chunked uploader has two modes of operation, Data Mode and Transaction Mode. When using data mode do not create a transaction, this will be done automatically for you.

Within Data Mode, you can either upload using:

  • A buffer containing the data you want to upload.
  • A readable stream pointing to the data you want to upload.

uploader.uploadData()

const transactionOptions = { tags: [{ name: "Content-Type", value: "text/plain" }] };
 
// 1. Upload a Buffer containing just the data you want to upload.
const dataBuffer = Buffer.from("Hirys, world!");
const response = await uploader.uploadData(dataBuffer, transactionOptions);
// The transaction ID (used to query the network) is found in response.data.id
console.log(`Data buffer uploaded ==> https://gateway.irys.xyz/${response.data.id}`);
 
// 2. OR Upload a Readable (stream) pointing to the data
uploader = irys.uploader.chunkedUploader; // Recreate for each transaction
const dataStream = fs.createReadStream("./data.txt");
response = await uploader.uploadData(dataStream, transactionOptions);
console.log(`Read Stream uploaded ==> https://gateway.irys.xyz/${response.data.id}`);