Skip to content

Post signed data to Arweave using @liteseed/sdk

In this tutorial, we will walkthrough the process of uploading data to Arweave using the @liteseed/sdk.

This tutorial requires the installation of the @liteseed/sdk.

Terminal window
npm install @liteseed/sdk

@liteseed/sdk is the official js library for interacting with the Liteseed for js/ts.

The sdk makes it very easy to upload data.

First, you must create a new instance of Liteseed with the private key (JWK) you will use to sign and upload the data.

import { readFileSync } from "fs";
import { Liteseed } from "@liteseed/sdk";
const jwk = JSON.parse(readFileSync("./arweave.json").toString());
const liteseed = new Liteseed(jwk);

You can convert any data into a special arweave transaction using signData.

const data = readFileSync("image.jpeg");
const dataItem = await liteseed.signData({ data });

Store the id in a database, so you can query your data later easily.

Next, you must pay for the upload to complete the process. You can check for the price of upload as follows.

const receipt = await liteseed.postSignedData({ dataItem });
console.log(receipt);

The receipt object looks something like the following The response would look something like this

{
"id": "kscLYZ3UHdCUZAimSr6wrSl5v-ll8uOQr_G8ZQ4osYA",
"dataCaches": ["api.liteseed.xyz"],
"fastFinalityIndexes": ["api.liteseed.xyz"],
"deadlineHeight": 1470374,
"owner": "...",
"version": "1.0.0"
}

Finally, you need to simply make the payment.

const payment = await liteseed.sendPayment({ dataItem });
console.log(payment);

Here’s the complete code for uploading a data-item using the @liteseed/sdk.

import { readFileSync } from "node:fs";
import { Liteseed } from "@liteseed/sdk";
const jwk = JSON.parse(readFileSync("./arweave.json").toString());
const liteseed = new Liteseed(jwk);
const data = readFileSync("image.jpeg");
async function upload(data) {
const dataItem = await liteseed.signData({ data });
const receipt = await liteseed.postSignedData({ dataItem });
console.log(receipt);
const payment = await liteseed.sendPayment({ dataItem });
console.log(payment);
}
upload(data);