Usage
Last updated
Was this helpful?
Last updated
Was this helpful?
Below is a quick example of how to initialize the Arweave Data Storage SDK,create a drive, a folder, and a file, or quickly upload a file. For more detailed use-cases, refer to the section.
To use the SDK, initialize StorageApi with a configuration object. This will create a new Arweave Data Storage SDK client. You may also specify the application name (appName
) and optional configurations.
Once you have the storage client initialized and before you go ahead to upload any files, its really important to create a secured session by authenticating yourself. This allows you to track or query your uploads, receipts. It is easy and can be done in one line.
And that's it. You’re ready to make authenticated requests with the service.
Assuming you have a valid session post login, the next step is to query for file upload prices. This is an optional step, in-case you are interested in setting up uploads conditionally or to check your wallet for enough balance before your upload. Based on your selected token and network, estimates will be provided to you in the same token and also in USD.
Upload a file (or buffer) quickly using the quickUpload method.
The quickUpload
method simplifies the process of uploading a file to Arweave. It automatically handles the creation of the transaction, including setting metadata such as content type, visibility, and tags. The receipt returned includes the unique ID, to query and confirm the file upload.
Create a new drive to manage your files on Arweave.
Drives act as containers for your files and folders. The additional parameters such as visibility and tags help you categorize and control access to your content. This context is useful if you’re new to managing storage on decentralized platforms.
Organize your files by creating folders within a drive.
Folders help you structure your files within a drive. In this example, you can see how to specify the parent drive and (optionally) a parent folder to build a hierarchical file system.
Store a file on Arweave by creating a file transaction.
This snippet creates a file by converting a string into a buffer and then sending it as a transaction to Arweave. The parameters include metadata like file name, size, and content type.
Note: The visibility
field can be set to public
or private
.