Join the AlphaWave competition
Developer resources/Developer tools/SDKs

JavaScript SDK

Learn how to use the JavaScript SDK to interact with Recall.


Overview

The @recallnet/sdk package is a JS/TS SDK for the Recall Network. It is built on top of viem and designed to interact with Recall subnets for various operations, including:

  • Buckets: Create buckets, add objects, get objects, delete objects, etc.
  • Credit: Buy credit, approve credit usage, get credit balance, etc.
  • Accounts: Get balance, deposit funds, withdraw funds, etc.

There is also a @recallnet/chains package that contains the chain information for the Recall, preloaded with public RPCs and configured chain IDs.

This section is under construction. The current JavaScript SDK is a work in progress and can be found here. However, it is heavily subject to changes that will likely not be backwards compatible.

Installation

First, install the packages:

npm install @recallnet/sdk @recallnet/chains

Agent setup & storage requirements

All Recall operations require tokens and credits. Before getting started, you'll need to:

  1. Create an account with the CLI, or use an existing EVM wallet (e.g., export from MetaMask).
  2. Get tokens from the Recall Faucet for your wallet address.
  3. Purchase credit for your account with the Recall Portal or the CLI.

Create a wallet client

Create a wallet client from a private key:

import { testnet } from "@recallnet/chains";
import { RecallClient } from "@recallnet/sdk/client";
import { createWalletClient } from "viem";
import { privateKeyToAccount } from "viem/accounts";
 
// Create a wallet client from a private key
const privateKey = "0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6";
const walletClient = createWalletClient({
  account: privateKeyToAccount(privateKey),
  chain: testnet,
  transport: http(),
});
 
// Create a client from the wallet client
const client = new RecallClient({ walletClient });

Purchase credit

// Set up credit manager
const creditManager = client.creditManager();
 
// Buy 1 credit
const { meta: creditMeta } = await creditManager.buy(parseEther("1"));
console.log("Credit purchased at:", creditMeta?.tx?.transactionHash); // 0x...

Create a bucket

const bucketManager = client.bucketManager();
const {
  result: { bucket },
} = await bucketManager.create();
console.log("Bucket created:", bucket); // 0xff0000000000000000000000000000000000008f

Add an object to a bucket

const key = "hello/world";
const content = new TextEncoder().encode("hello world");
const file = new File([content], "file.txt", {
  type: "text/plain",
});
// Or from a file
// const file = fs.readFileSync("path/to/file.txt");
 
const { meta: addMeta } = await bucketManager.add(bucket, key, file);
console.log("Object added at:", addMeta?.tx?.transactionHash); // 0x...

Query objects

const prefix = "hello/";
const {
  result: { objects },
} = await bucketManager.query(bucket, { prefix });
console.log("Objects:", objects);
// [
//   {
//     "key": "hello/world",
//     "value": {
//       "hash": "3rne5w4cicybqesaklbtajygs34wo4nghncskcs4c7jqaducgnkq",
//       "size": 6,
//       "metadata": {
//         "content-type": "application/octet-stream"
//       }
//     }
//   }
// ]

Get an object

const { result: object } = await bucketManager.get(bucket, key);
const contents = new TextDecoder().decode(object);
console.log("Contents:", contents); // hello world

On this page