import {readFileSync} from "fs";
import Arweave from "arweave";
* @param {Arweave} arweave
async function sendPaymentTransaction(size, jwk, arweave) {
const response = await fetch(`https://api.liteseed.xyz/price/${size}`);
const {price, address} = await response.json();
console.log("Price in AR", price); // Price of upload
console.log("Address to pay", address); // The wallet to pay
const tx = await arweave.createTransaction({quantity: price, target: address}, jwk);
await arweave.transactions.sign(tx, jwk);
await arweave.transactions.post(tx);
console.log("Transaction Id", tx.id);
* @returns {Promise<{id: string; owner: string; dataCaches: string[]; fastFinalityIndexes: string[]; version: string; deadlineHeight: number;}>}
async function postData(file, size) {
const body = new FormData();
body.append("file", file);
body.append("tags[]", "image");
body.append("tags[]", "image/jpeg");
const response = await fetch(`https://api.liteseed.xyz/data`, {
headers: {"content-length": size.toString(), "content-type": "application/octet-stream"}
const receipt = await response.json();
console.log("Receipt", receipt);
* @param paymentId {string}
* @returns {Promise<any>}
async function updatePaymentId(id, paymentId) {
const response = await fetch(`https://api.liteseed.xyz/tx/${id}/${paymentId}`, {method: "PUT"});
const payment = await response.json();
console.log("Payment", payment);
async function uploadFile() {
const file = readFileSync("file.jpeg"); // The file to upload
const jwk = JSON.parse(readFileSync("./keyfile.json").toString());
const arweave = Arweave.init({
const receipt = await postData(file, size);
const tx = await sendPaymentTransaction(size, jwk, arweave);
await updatePaymentId(receipt.id, tx.id);
uploadFile().then(() => console.log("success"));