Post using SDK
- Sign your payload into a Data-Item using
arbundles
- Post the Data-Item to Liteseed’s staging endpoint
- Pay the required AR fee on Arweave
- Notify the network to bundle and commit on-chain
Background
Section titled “Background”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:
Deep dive into the format here: ANS-104: Bundled Data v2.0
Prerequisites
Section titled “Prerequisites”npm install arweave arbundles @liteseed/sdk
yarn add arweave arbundles @liteseed/sdk
pnpm add arweave arbundles @liteseed/sdk
bun add arweave arbundles @liteseed/sdk
You also need a valid Arweave JWK keyfile (e.g. jwk.json
).
Sign Data
Section titled “Sign Data”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;}
// Usageconst 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);
Post to Liteseed
Section titled “Post to Liteseed”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);
Pay Upload Fee
Section titled “Pay Upload Fee”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);
Notify Network
Section titled “Notify Network”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);
Complete Script
Section titled “Complete Script”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!');})();