For this example we’ll use the image below and save it on Arweave.
Installing the required packages
This tutorial requires some packages to make uploading data easier.
arweave is the official js library for interacting with the Arweave library.
arbundles is the recommended library for converting data into data-item.
Uploading using a DataItem
A data-item is a special format to upload data onto Arweave.
It is designed for upload a large number of transactions.
Posting the DataItem to the API
The data-item is sent to the API using a post request.
The request expects a header "application/octet-stream" and the size of the data-item.
The response would look something like this
Store the id in a database, so you can query your data later easily.
Calculating price of upload
Next we fetch the price of the upload and create a transaction to pay for the upload.
Updating the Payment Information
Next, you need let the network know of the payment.
Once the payment is confirmed (approximately >20 blocks on Arweave are mined), you data will be sent to Arweave in a bundle.
Here the id is the id in the receipt object from the previous function call.