JavaScript/TypeScript client library for the Arweave decentralized permanent data storage network
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Complete transaction lifecycle management including creation, signing, submission, verification, and status monitoring. Handles both data storage and AR transfer transactions.
Create a new transaction for either data storage or AR transfers.
/**
* Create a new transaction
* @param attributes - Transaction attributes
* @param jwk - Wallet key or "use_wallet" for browser wallet
* @returns Promise resolving to a Transaction instance
*/
createTransaction(
attributes: Partial<CreateTransactionInterface>,
jwk?: JWKInterface | "use_wallet"
): Promise<Transaction>;Usage Examples:
import Arweave from "arweave";
const arweave = Arweave.init();
const key = await arweave.wallets.generate();
// Data transaction
const dataTransaction = await arweave.createTransaction({
data: "Hello, Arweave!"
}, key);
// AR transfer transaction
const paymentTransaction = await arweave.createTransaction({
target: "target-wallet-address",
quantity: arweave.ar.arToWinston("0.1") // 0.1 AR
}, key);
// Transaction with tags
const taggedTransaction = await arweave.createTransaction({
data: JSON.stringify({ message: "Hello World" }),
tags: [
{ name: "Content-Type", value: "application/json" },
{ name: "App-Name", value: "MyApp" }
]
}, key);Sign a transaction with a wallet's private key.
/**
* Sign a transaction
* @param transaction - Transaction to sign
* @param jwk - Wallet key or "use_wallet" for browser wallet
* @param options - Signing options
*/
sign(
transaction: Transaction,
jwk?: JWKInterface | "use_wallet",
options?: SignatureOptions
): Promise<void>;Usage Example:
const transaction = await arweave.createTransaction({ data: "Hello!" }, key);
await arweave.transactions.sign(transaction, key);
console.log("Transaction signed:", transaction.id);Submit a signed transaction to the Arweave network.
/**
* Submit a transaction to the network
* @param transaction - Signed transaction to submit
* @returns Promise resolving to HTTP response details
*/
post(transaction: Transaction | Buffer | string | object): Promise<{
status: number;
statusText: string;
data: any;
}>;Usage Example:
const transaction = await arweave.createTransaction({ data: "Hello!" }, key);
await arweave.transactions.sign(transaction, key);
const response = await arweave.transactions.post(transaction);
console.log("Transaction posted:", response.status);Retrieve a transaction by its ID.
/**
* Retrieve a transaction by ID
* @param id - Transaction ID
* @returns Promise resolving to Transaction instance
*/
get(id: string): Promise<Transaction>;Usage Example:
const transaction = await arweave.transactions.get("transaction-id");
console.log("Transaction data:", transaction.get("data", { decode: true, string: true }));Check the confirmation status of a transaction.
/**
* Get transaction confirmation status
* @param id - Transaction ID
* @returns Promise resolving to status information
*/
getStatus(id: string): Promise<TransactionStatusResponse>;Usage Example:
const status = await arweave.transactions.getStatus("transaction-id");
if (status.confirmed) {
console.log(`Confirmed in block ${status.confirmed.block_height}`);
} else {
console.log("Transaction pending");
}Retrieve the data payload from a transaction.
/**
* Get transaction data
* @param id - Transaction ID
* @param options - Decoding options
* @returns Promise resolving to data as string or Uint8Array
*/
getData(
id: string,
options?: { decode?: boolean; string?: boolean }
): Promise<string | Uint8Array>;Usage Example:
// Get raw data
const rawData = await arweave.transactions.getData("transaction-id");
// Get decoded string data
const stringData = await arweave.transactions.getData("transaction-id", {
decode: true,
string: true
});Verify the cryptographic signature of a transaction.
/**
* Verify transaction signature
* @param transaction - Transaction to verify
* @returns Promise resolving to verification result
*/
verify(transaction: Transaction): Promise<boolean>;Usage Example:
const transaction = await arweave.transactions.get("transaction-id");
const isValid = await arweave.transactions.verify(transaction);
console.log("Transaction valid:", isValid);Create a Transaction instance from raw transaction attributes.
/**
* Create Transaction from raw attributes
* @param attributes - Raw transaction attributes
* @returns Transaction instance
*/
fromRaw(attributes: object): Transaction;Get a suitable anchor (last transaction ID) for creating new transactions.
/**
* Get transaction anchor for new transactions
* @returns Promise resolving to anchor string
*/
getTransactionAnchor(): Promise<string>;Calculate the cost in winston for a transaction of given size.
/**
* Get transaction price
* @param byteSize - Size of transaction data in bytes
* @param targetAddress - Optional target address for AR transfers
* @returns Promise resolving to price in winston
*/
getPrice(byteSize: number, targetAddress?: string): Promise<string>;Usage Example:
const data = "Hello, Arweave!";
const dataSize = new TextEncoder().encode(data).length;
const price = await arweave.transactions.getPrice(dataSize);
console.log(`Transaction cost: ${arweave.ar.winstonToAr(price)} AR`);class Transaction {
/** Transaction format version */
readonly format: number;
/** Transaction ID */
id: string;
/** Last transaction anchor */
readonly last_tx: string;
/** Owner public key */
owner: string;
/** Transaction tags */
tags: Tag[];
/** Target wallet address */
readonly target: string;
/** AR amount to transfer */
readonly quantity: string;
/** Data size in bytes */
readonly data_size: string;
/** Transaction data */
data: Uint8Array;
/** Merkle root of data */
data_root: string;
/** Transaction fee */
reward: string;
/** Transaction signature */
signature: string;
/** Computed chunks for upload */
chunks: object;
}/**
* Get transaction field with optional decoding
* @param field - Field name to retrieve
* @param options - Decoding options
* @returns Field value as string, Uint8Array, or Tag array
*/
get(field: string, options?: { decode?: boolean; string?: boolean }): string | Uint8Array | Tag[];
/**
* Add a tag to the transaction
* @param name - Tag name
* @param value - Tag value
*/
addTag(name: string, value: string): void;
/**
* Serialize transaction to JSON
* @returns Plain object representation
*/
toJSON(): object;
/**
* Set transaction owner
* @param owner - Owner public key
*/
setOwner(owner: string): void;
/**
* Prepare data chunks for upload
* @param data - Transaction data
*/
prepareChunks(data: Uint8Array): Promise<void>;
/**
* Get signature data for signing
* @returns Data that should be signed
*/
getSignatureData(): Promise<Uint8Array>;interface CreateTransactionInterface {
/** Transaction format version */
format: number;
/** Last transaction anchor */
last_tx: string;
/** Owner public key */
owner: string;
/** Transaction tags */
tags: Tag[];
/** Target wallet address */
target: string;
/** AR amount to transfer */
quantity: string;
/** Transaction data */
data: string | Uint8Array | ArrayBuffer;
/** Data size in bytes */
data_size: string;
/** Merkle root of data */
data_root: string;
/** Transaction fee */
reward: string;
}interface TransactionStatusResponse {
/** HTTP status code */
status: number;
/** Confirmation data if confirmed */
confirmed: TransactionConfirmedData | null;
}
interface TransactionConfirmedData {
/** Block height where confirmed */
block_height: number;
/** Independent hash of confirming block */
block_indep_hash: string;
/** Number of confirmations */
number_of_confirmations: number;
}class Tag {
/** Tag name */
readonly name: string;
/** Tag value */
readonly value: string;
/**
* Create a transaction tag
* @param name - Tag name
* @param value - Tag value
* @param decode - Whether to decode base64 values
*/
constructor(name: string, value: string, decode?: boolean);
}interface SignatureOptions {
/** PSS salt length for RSA-PSS signatures */
saltLength?: number;
}