Skip to main content

Overview

Arcium provides two TypeScript libraries for interacting with Arcium and deployed MXEs (MPC eXecution Environments). Client library @arcium-hq/client:
  • Handles secret sharing and encryption of inputs
  • Submits encrypted transactions
  • Manages callbacks for computation results
Reader library @arcium-hq/reader:
  • Reads MXE data
  • Views computations for a given MXE
Use the client library to build and invoke computations on MXEs, then track their outputs. Use the reader library to inspect MXE and network state. For the full flow, see the computation lifecycle.

Installation

Client library:
npm install @arcium-hq/client
yarn add @arcium-hq/client
pnpm add @arcium-hq/client
Reader library:
npm install @arcium-hq/reader
yarn add @arcium-hq/reader
pnpm add @arcium-hq/reader

API reference

For complete TypeScript SDK documentation, see the API reference.

Reclaiming computation rent

Every queued computation allocates a Solana account that holds rent. After the computation lifecycle completes, you should reclaim that rent.

After successful finalization

Once a computation reaches Finalized status (after the callback executes), use claimComputationRent to close the account and reclaim the rent:
import { claimComputationRent } from '@arcium-hq/client';

const sig = await claimComputationRent(
    provider,           // AnchorProvider
    clusterOffset,      // cluster the computation was queued on
    computationOffset,  // BN - the offset used when queueing
);
The signer must be the original payer who queued the computation. Using a different signer will fail with InvalidAuthority.
Computations that remain in Queued status expire after 180 slots (~72 seconds). Expired computations can be reclaimed using the reclaimExpiredComputationFee instruction, which also returns any fees from the fee pool. See the API reference for details.
claimComputationRent only closes per-computation accounts. To close long-lived MXE or computation-definition accounts, see Account lifecycle and closing.

Reading computation fees

The reader library exposes two getters for inspecting a computation’s fee, depending on whether its account is still open:
import { getComputationFee, getComputationFeeFromQueueTx } from '@arcium-hq/reader';

// Live computation: reads the onchain fee from the open account.
// Returns null once the account is closed (rent reclaimed).
const fee = await getComputationFee(
    arciumProgram,
    mxeProgramId,
    computationOffset,
);

// Closed computation: reconstructs the queue-time fee inputs by decoding
// the original queue_computation instruction from its transaction signature.
const queued = await getComputationFeeFromQueueTx(
    arciumProgram,
    queueTxSignature,
    mxeProgramId,
    computationOffset,
);
getComputationFee returns { source: 'account', ... } with the live onchain fee, or null when the account has been closed. getComputationFeeFromQueueTx returns { source: 'queueTx', ... } with the raw queue-time inputs (not lamport amounts) and requires an archive RPC that retains the original transaction and its inner instructions. See the API reference for the full return shapes.

Using the client

Prefer a more step-by-step approach? Get started with learning how to encrypt inputs for encrypted transactions.

What’s next?

Encrypting inputs

Step-by-step guide to encrypting data for encrypted transactions.

Tracking callbacks

Await and process computation results.

Full API reference

Complete TypeScript SDK documentation.