uploadFile(fileName, tags?)
Uploads a file to Irys.
Parameters
Name
Type
Description
fileName
string
Name of the file to upload.
Returns
Type
Description
object
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 the transaction was created and 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 the transaction must be finalized
block, // Deprecated
validatorSignatures, // Deprecated
verify, // An async function used to verify the receipt at any time
}
Funding
Uploads of less than 100 KiB are are free. For larger uploads, you'll need to fund your account first.
Example
ℹ️
Use a token-specific version of getIrysUploader()
to connect to an Irys Bundler before uploading. Choose one from here.
const irys = await getIrysUploader();
// Your file
const fileToUpload = "./myImage.png";
// Add a custom tag that tells the gateway how to serve this file to a browser
const tags = [{ name: "Content-Type", value: "image/png" }];
try {
const response = await irys.uploadFile(fileToUpload, tags);
console.log(`File uploaded ==> https://gateway.irys.xyz/${response.id}`);
} catch (e) {
console.log("Error uploading file ", e);
}
ℹ️
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.