Skip to content

Post using SDK

  1. Sign your payload into a Data-Item using arbundles
  2. Post the Data-Item to Liteseed’s staging endpoint
  3. Pay the required AR fee on Arweave
  4. Notify the network to bundle and commit on-chain

Arweave stores data permanently via transactions. Liteseed Network batches multiple Data-Items into a single Arweave transaction (a bundle) to reduce fees and complexity. This tutorial uses:

  • arweave: official JS client for Arweave
  • arbundles: library for creating & signing Data-Items

Deep dive into the format here: ANS-104: Bundled Data v2.0

Terminal window
npm install arweave arbundles @liteseed/sdk

You also need a valid Arweave JWK keyfile (e.g. jwk.json).


Convert your binary payload or string into a signed Data-Item:

import { readFileSync } from 'fs';
import { ArweaveSigner, createData, type DataItem } from 'arbundles/node';
async function signData(data: Uint8Array | string, jwk: any): Promise<DataItem> {
const signer = new ArweaveSigner(jwk);
const dataItem = await createData(data, signer);
await dataItem.sign(signer);
return dataItem;
}
// Usage
const jwk = JSON.parse(readFileSync('./jwk.json', 'utf-8'));
const file = readFileSync('file.jpeg');
const dataItem = await signData(file, jwk);
console.log('Data-Item ID:', dataItem.id);

Send the raw Data-Item bytes to the staging API:

type Receipt = {
id: string;
dataCaches: string[];
fastFinalityIndexes: string[];
deadlineHeight: number;
owner: string;
version: string;
};
async function postData(dataItem: DataItem): Promise<Receipt> {
const raw = dataItem.getRaw();
const res = await fetch('https://api.liteseed.xyz/tx', {
method: 'POST',
headers: {
'Content-Type': 'application/octet-stream',
'Content-Length': raw.length.toString()
},
body: raw
});
if (!res.ok) throw new Error(`Post failed: ${res.status}`);
return res.json();
}
const receipt = await postData(dataItem);
console.log('Receipt:', receipt);

Fetch the price and submit an AR transaction:

import Arweave from 'arweave';
async function sendPayment(size: number, jwk: any): Promise<string> {
const res = await fetch(`https://api.liteseed.xyz/price/${size}`);
if (!res.ok) throw new Error('Price lookup failed');
const { price, address } = await res.json();
const ar = Arweave.init({ host: 'arweave.net', protocol: 'https' });
const tx = await ar.createTransaction({ target: address, quantity: price }, jwk);
await ar.transactions.sign(tx, jwk);
const postRes = await ar.transactions.post(tx);
if (postRes.status !== 200) throw new Error('Payment failed');
console.log('⛓️ Payment TX ID:', tx.id);
return tx.id;
}
const paymentId = await sendPayment(dataItem.getRaw().length, jwk);

Inform Liteseed of your AR payment so it can finalize the on-chain bundle:

async function notifyNetwork(uploadId: string, paymentId: string) {
const res = await fetch(`https://api.liteseed.xyz/tx/${uploadId}/${paymentId}`, {
method: 'PUT'
});
if (!res.ok) throw new Error('Notification failed');
console.log('✅ Bundle committed:', await res.json());
}
await notifyNetwork(receipt.id, paymentId);

import { readFileSync } from 'fs';
import { ArweaveSigner, createData } from 'arbundles/node';
import Arweave from 'arweave';
(async function() {
const jwk = JSON.parse(readFileSync('./jwk.json', 'utf-8'));
const signer = new ArweaveSigner(jwk);
const buffer = readFileSync('file.jpeg');
// 1️⃣ Sign
const dataItem = await createData(buffer, signer);
await dataItem.sign(signer);
// 2️⃣ Post
const raw = dataItem.getRaw();
const postRes = await fetch('https://api.liteseed.xyz/tx', {
method: 'POST', headers: {
'Content-Type': 'application/octet-stream',
'Content-Length': raw.length.toString()
}, body: raw
});
const receipt = await postRes.json();
// 3️⃣ Pay
const { price, address } = await (await fetch(`https://api.liteseed.xyz/price/${raw.length}`)).json();
const ar = Arweave.init({ host: 'arweave.net', protocol: 'https' });
const tx = await ar.createTransaction({ target: address, quantity: price }, jwk);
await ar.transactions.sign(tx, jwk);
await ar.transactions.post(tx);
// 4️⃣ Notify
await fetch(`https://api.liteseed.xyz/tx/${receipt.id}/${tx.id}`, { method: 'PUT' });
console.log('🎉 Upload complete!');
})();