Upload API
upload(data, tags?, anchor?)
Uploads data to Irys.
Parameters
| Name | Type | Description |
|---|---|---|
| data | string | Buffer | Readable | The data to upload. |
| tags | Tag[] | (Optional) Metatags. |
| anchor | string | (Optional) Random value used to prevent data item ID collisions, used with deterministic data item IDs only. |
Returns
Returns a receipt as a JSON object with the following values:
response = {
id, // Transaction ID (used to download the data)
timestamp, // Timestamp (UNIX milliseconds) of when created/verified
version, // The version of this JSON file, currently 1.0.0
public, // Public key of the bundler node used
signature, // A signed deep hash of the JSON receipt
deadlineHeight, // The block number by which transaction must finalize
block, // Deprecated
validatorSignatures, // Deprecated
verify, // An async function used to verify receipt at any time
}Funding
Note
Uploads of less than 100 KiB are free. For larger uploads, you'll need to fund your account first.
Example
Note
Use a token-specific version of
getIrysUploader() to connect to an Irys Bundler before uploading. Choose one from the setup documentation.const irys = await getIrysUploader();
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);
}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.