Prerequisites

We require node version 18 or later version and npm version 8 to be installed in your environment. To install node and npm, we recommend you go to the Node.js official website and download the latest LTS (Long Term Support) version.

Install the Dependencies

Install the Story SDK node package, as well as viem.

npm install --save @story-protocol/core-sdk viem

Initiate SDK Client

Next we can initiate the SDK Client. There are two ways to do this:

  1. Using a private key (preferable for some backend admin)
  2. JSON-RPC account like Metamask where users sign their own transactions

Set Up Private Key Account

Before continuing with the code below:

  1. Make sure to have WALLET_PRIVATE_KEY set up in your .env file.
  2. Make sure to have RPC_PROVIDER_URL set up in your .env file.
    • You can use the public default one (https://aeneid.storyrpc.io) or check out the other RPCs here.
utils.ts
import { http } from "viem";
import { Account, privateKeyToAccount, Address } from "viem/accounts";
import { StoryClient, StoryConfig } from "@story-protocol/core-sdk";

const privateKey: Address = `0x${process.env.WALLET_PRIVATE_KEY}`;
const account: Account = privateKeyToAccount(privateKey);

const config: StoryConfig = {
  account: account, // the account object from above
  transport: http(process.env.RPC_PROVIDER_URL),
  chainId: "aeneid",
};
export const client = StoryClient.newClient(config);

Setup for React (ex. Metamask)

The React Setup Guide shows how we can also use the TypeScript SDK to delay signing & sending transactions to a JSON-RPC account like Metamask.