Upload API
uploader.uploadBundle(tx, bundleOptions?)
Enables users to upload an array of transactions as a single bundled transaction.
While this function exists for obtaining transaction IDs beforehand, most developers should use uploadFolder() instead, which handles uploading, signing, and bundling automatically.
Parameters
| Name | Type | Description |
|---|---|---|
| data | (DataItem | Buffer | string)[] | Array of transactions to upload. |
| bundleOptions | DataItemCreateOptions | (Optional) Upload settings including tags. |
The function automatically signs unsigned transactions using a temporary throwaway key, enabling transactions to be associated with a randomly-generated address. When buffers are provided, they are converted to transactions and signed by the throwaway key. The method returns the throwaway key, address, and all bundled transactions.
Returns
Returns an object with the following value:
response = {
id, // Transaction ID (used to download the data)
}The response also carries the fields of the legacy receipt object. They are kept for backwards compatibility, are not documented, and should not be relied on.
Funding
Example
getIrysUploader() to connect to an Irys Bundler before uploading. Choose one from the setup documentation.const uploadBundle = async () => {
const irys = await getIrysUploader();
const maxTxs = 5;
const txs = [];
// First create and sign a group of transactions
for (let i = 0; i < maxTxs; i++) {
const newTx = await irys.createTransaction(`Hirys World! ${i + 1}`, {
tags: [{ name: "Content-Type", value: "text/plain" }],
});
await newTx.sign(); // ID is now set
txs.push(newTx);
}
// Or send an array of Buffers
// If a Buffer is provided, it is converted into a transaction and then signed by the throwaway key
// const txs: Buffer[] = [
// Buffer.from("This is transaction data 1"),
// Buffer.from("This is transaction data 2"),
// ];
try {
const options = {
// throwawayKey: undefined, // Optional, pass a JWK if you have a throwaway key
bundleOpts: {
tags: [
{ name: "application-id", value: "foo" }, // Add optional tags
],
}
};
const response = await irys.uploader.uploadBundle(txs, options);
console.log(`All Txs uploaded.`);
for (let i = 0; i < response.txs.length; i++) {
console.log(`https://gateway.irys.xyz/${response.txs[i].id}`);
}
} catch (e) {
console.log("Error uploading bundle ", e);
}
};Downloading
Use the transaction ID returned as part of the response to download the data by creating a URL in the format https://gateway.irys.xyz/:transactionId.