JavaScript/TypeScript client library for the Arweave decentralized permanent data storage network
npx @tessl/cli install tessl/npm-arweave@1.15.0Arweave is a comprehensive JavaScript/TypeScript client library for interacting with the Arweave network, a decentralized permanent data storage protocol. It enables developers to create and manage wallets, send transactions, store data permanently on the Arweave permaweb, query blockchain data, and perform various blockchain operations. The library supports both Node.js and web browser environments with seamless integration.
npm install arweaveimport Arweave from "arweave";For CommonJS:
const Arweave = require("arweave");import Arweave from "arweave";
// Initialize Arweave client
const arweave = Arweave.init({
host: "arweave.net",
port: 443,
protocol: "https"
});
// Generate a new wallet
const key = await arweave.wallets.generate();
const address = await arweave.wallets.jwkToAddress(key);
// Check wallet balance
const balance = await arweave.wallets.getBalance(address);
console.log(arweave.ar.winstonToAr(balance));
// Create and post a data transaction
const transaction = await arweave.createTransaction({
data: "Hello, Arweave!"
}, key);
await arweave.transactions.sign(transaction, key);
await arweave.transactions.post(transaction);Arweave is built around several key components:
Arweave class providing factory initialization and unified transaction creationwallets, transactions, network, blocks, ar, silo, chunks) for different operationsArweave.crypto for cryptographic operations and Arweave.utils for data conversionCore Arweave client initialization and configuration for connecting to Arweave nodes.
static init(apiConfig?: ApiConfig): Arweave;
interface ApiConfig {
host?: string;
protocol?: string;
port?: string | number;
timeout?: number;
logging?: boolean;
logger?: Function;
network?: string;
}Comprehensive wallet management including generation, address derivation, and balance queries.
// Main wallet operations
getBalance(address: string): Promise<string>;
generate(): Promise<JWKInterface>;
jwkToAddress(jwk?: JWKInterface | "use_wallet"): Promise<string>;
getAddress(jwk?: JWKInterface | "use_wallet"): Promise<string>;Complete transaction lifecycle management including creation, signing, submission, and monitoring.
// Core transaction methods
createTransaction(attributes: Partial<CreateTransactionInterface>, jwk?: JWKInterface | "use_wallet"): Promise<Transaction>;
sign(transaction: Transaction, jwk?: JWKInterface | "use_wallet", options?: SignatureOptions): Promise<void>;
post(transaction: Transaction | Buffer | string | object): Promise<{status: number; statusText: string; data: any}>;
get(id: string): Promise<Transaction>;
getStatus(id: string): Promise<TransactionStatusResponse>;Advanced data upload capabilities with chunked uploading for large files and progress monitoring.
// Upload management
getUploader(upload: Transaction | SerializedUploader | string, data?: Uint8Array | ArrayBuffer): Promise<TransactionUploader>;
upload(upload: Transaction | SerializedUploader | string, data: Uint8Array): AsyncGenerator<TransactionUploader>;
// Chunk operations
getChunk(offset: string | number | BigInt): Promise<TransactionChunkResponse>;
downloadChunkedData(id: string): Promise<Uint8Array>;Network information queries, peer discovery, and block data retrieval.
// Network operations
getInfo(): Promise<NetworkInfoInterface>;
getPeers(): Promise<PeerList>;
// Block operations
get(indepHash: string): Promise<BlockData>;
getCurrent(): Promise<BlockData>;
getByHeight(height: number): Promise<BlockData>;Network and Blockchain Operations
AR/winston currency conversion and arithmetic operations for handling Arweave's native currency.
// Currency conversion
winstonToAr(winstonString: string, options?): string;
arToWinston(arString: string, options?): string;
// Currency arithmetic
compare(winstonStringA: string, winstonStringB: string): number;
add(winstonStringA: string, winstonStringB: string): string;
sub(winstonStringA: string, winstonStringB: string): string;Low-level cryptographic functions for signing, verification, encryption, and hashing.
// Key management
generateJWK(): Promise<JWKInterface>;
// Signing and verification
sign(jwk: JWKInterface, data: Uint8Array, options?: SignatureOptions): Promise<Uint8Array>;
verify(publicModulus: string, data: Uint8Array, signature: Uint8Array): Promise<boolean>;
// Encryption and hashing
encrypt(data: Uint8Array, key: string | Uint8Array, salt?: string): Promise<Uint8Array>;
hash(data: Uint8Array, algorithm?: string): Promise<Uint8Array>;Utility functions for data conversion, encoding/decoding, and buffer manipulation.
// Buffer/string conversion
stringToBuffer(string: string): Uint8Array;
bufferToString(buffer: Uint8Array | ArrayBuffer): string;
// Base64 URL encoding/decoding
bufferTob64Url(buffer: Uint8Array): string;
b64UrlToBuffer(b64UrlString: string): Uint8Array;Silo protocol implementation for encrypted data storage with URI-based access control.
// Silo operations
get(siloURI: string): Promise<Uint8Array>;
parseUri(siloURI: string): Promise<SiloResource>;
createSiloTransaction(attributes: Partial<CreateTransactionInterface>, jwk: JWKInterface, siloUri: string): Promise<Transaction>;The following APIs are deprecated and maintained for backward compatibility:
// Deprecated ArQL query method (use GraphQL instead)
arql(query: object): Promise<string[]>;
// Deprecated transaction search (use GraphQL instead)
search(tagName: string, tagValue: string): Promise<string[]>;
// Deprecated instance access to static utilities
get crypto(): CryptoInterface; // Use Arweave.crypto instead
get utils(): ArweaveUtilsInterface; // Use Arweave.utils insteadinterface JWKInterface {
kty: string;
e: string;
n: string;
d?: string;
p?: string;
q?: string;
dp?: string;
dq?: string;
qi?: string;
}
interface Tag {
name: string;
value: string;
}
interface CreateTransactionInterface {
format: number;
last_tx: string;
owner: string;
tags: Tag[];
target: string;
quantity: string;
data: string | Uint8Array | ArrayBuffer;
data_size: string;
data_root: string;
reward: string;
}
interface ArweaveUtilsInterface {
/** Convert string to Uint8Array buffer */
stringToBuffer(string: string): Uint8Array;
/** Convert buffer to UTF-8 string */
bufferToString(buffer: Uint8Array | ArrayBuffer): string;
/** Convert buffer to base64url string */
bufferTob64Url(buffer: Uint8Array): string;
/** Convert base64url string to buffer */
b64UrlToBuffer(b64UrlString: string): Uint8Array;
/** Convert string to base64url */
stringToB64Url(string: string): string;
/** Convert base64url to string */
b64UrlToString(b64UrlString: string): string;
/** Concatenate multiple buffers */
concatBuffers(buffers: Uint8Array[] | ArrayBuffer[]): Uint8Array;
}