How to run Story Protocol Node (EP2) — SDK & Wallet

In this episode, I’d like to share how I installed the SDK, created a wallet, and set up a client. This is still on the Sepolia testnet…

How to run Story Protocol Node (EP2) — SDK & Wallet

In this episode, I’d like to share how I installed the SDK, created a wallet, and set up a client. This is still on the Sepolia testnet. As of the time I’m writing this, there is no information yet about the testnet in Story Protocol. When it’s released, I will update this document.

If you haven’t set up Story Protocol yet, you can check out my article here: How I Run Story Protocol Node. After installing the node, you might want to link your wallet to the node and start using the SDK. However, this article will not cover node deployment yet, as syncing the node on Sepolia is taking a while. Once the syncing is complete, I will update you further.

To interact with the node, you’ll need to install the Story Protocol SDK. Here’s how you can do it:

Prerequisites: Install npm

If you don’t have npm installed or if the version is outdated, you can execute the following command. However, you can skip this step if everything is already set up and up to date.

#install 
sudo apt install npm 
 
#update to V20 
nvm install 20 
nvm use 20

Step 3.1: Install the SDK

Once you have Node.js v20 installed, proceed to install the Story Protocol SDK and its dependencies:

npm install --save @story-protocol/core-sdk [email protected]

After the installation, you might be prompted to fix or update some packages. To do this, run:

npm audit fix --force

Following this command, I received a message indicating that the viem package was upgraded to version 2.20.0.

Step 3.2: Create a Wallet

Since the documentation for this early stage might be challenging to follow, I worked with ChatGPT to develop a script that simplifies the process. Here’s how you can create a wallet:

3.2.1 Create the Script File.

Start by creating a new file called createWallet.ts:

nano createWallet.ts

In the nano editor, paste the following script:

import { config } from "dotenv"; 
import { privateKeyToAccount } from "viem/accounts"; 
import type { Address } from "viem"; 
 
// Load environment variables from .env file 
config(); 
 
// Get the private key from the .env file 
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "0x"; 
 
// Create the account object using the private key 
const account = privateKeyToAccount(PRIVATE_KEY as Address); 
 
// Export the account object for use in other parts of your project 
export default account; 
 
// For demonstration, you can log the account address (not recommended for production) 
console.log(`Wallet address: ${account.address}`);

3.2.2 Create the .env File:

As indicated in the script, you’ll need to create a .env file to store your private key:

nano .env

In the nano editor, specify your private key as follows:

WALLET_PRIVATE_KEY=0xprivatekey

Replace "privatekey" with your actual hot wallet key. I strongly recommend using this wallet for testing purposes only. In my case, I created a new MetaMask wallet and extracted the private key from it.

3.2.3 Run the Script:

After setting everything up, you can run the script. The script will output the account address associated with your wallet:

npx ts-node createWallet.ts

This should provide you with the wallet address necessary for further steps in your project.

Step 3.3 Instantiate the client

Now that you have your wallet set up, the next step is to instantiate your client. Follow these steps:

3.3.1 Create the Client Setup Script:

First, create a new file called setupClient.ts:

nano setupClient.ts

In the nano editor, paste the following code:

import { config as loadEnv } from "dotenv"; 
import { Account, privateKeyToAccount, Address } from 'viem/accounts'; 
import { StoryClient, StoryConfig } from "@story-protocol/core-sdk"; 
import { http } from 'viem' 
 
// Load environment variables from .env file 
loadEnv(); 
 
// Get the private key from the .env file and ensure it's valid 
const privateKey: Address = process.env.WALLET_PRIVATE_KEY as Address; 
const account: Account = privateKeyToAccount(privateKey); 
 
// Configure the SDK client using the environment variables and the account 
const config: StoryConfig = { 
  transport: http(process.env.RPC_PROVIDER_URL), 
  account: account, // the account object from above 
  chainId: '1513' // change from Sepolia 
}; 
 
export const client = StoryClient.newClient(config); 
console.log("SDK Client is set up and ready to use.");

3.3.2 Update the .env File:

You’ll need to add a new variable to your .env file. Open the .env file:

nano .env
WALLET_PRIVATE_KEY=0xprivatekey 
RPC_PROVIDER_URL=https://rpc.partner.testnet.storyprotocol.net

3.3.3 Run the Client Setup Script:

After everything is set up, run the script to instantiate the client:

npx ts-node setupCleint.ts

Once the script runs successfully, your SDK will be ready to use. The fun part is just beginning!


Summary

In this guide, I demonstrated how to install the Story Protocol SDK, create a wallet, and set up a client on the Sepolia testnet. While node deployment isn’t covered due to syncing delays, the steps provided help you prepare for future interactions. Stay tuned for updates as the network evolves. Thank you for reading.