Solana Kit

Overview

Client-side Solana Kit for React and browser environments

React API

The React entry point provides client-side functionality for integrating Solana wallets with the Shelby Protocol. It's designed for browser applications where users connect their Solana wallets (Phantom, Solflare, etc.) to interact with Shelby storage.

Installation

npm install @shelby-protocol/solana-kit @shelby-protocol/sdk

For simplicity, also install the Shelby react package for react hooks helpers

npm install @shelby-protocol/react

Solana project setup

You'll also need a Solana wallet adapter. For example, with Solana Wallet Adapter:

npm install @solana/wallet-adapter-react @solana/wallet-adapter-wallets

Or simply set up your project with

npx create-solana-dapp

Usage

Import from the @shelby-protocol/solana-kit/react entry point:

"use client";

import { useStorageAccount, Network } from "@shelby-protocol/solana-kit/react";
import { useUploadBlobs } from "@shelby-protocol/react";
import { ShelbyClient } from "@shelby-protocol/sdk/browser";
import { useWallet } from "@solana/wallet-adapter-react";

function MyComponent() {
  // use Solana wallet hook
  const { publicKey, signMessage } = useWallet();

  // initiate Shelby client
  const shelbyClient = new ShelbyClient({
    network: Network.SHELBYNET,
    apiKey: "AG-***",
  });

  // use Shelby solana-kit hook
  const { storageAccountAddress, signAndSubmitTransaction } = useStorageAccount(
    {
      client: shelbyClient,
      solanaAddress: publicKey?.toBase58(),
      signMessageFn: signMessage,
    }
  );

  // use Shelby react package upload blob hook
  const { mutateAsync: uploadBlobs } = useUploadBlobs({
    client: shelbyClient,
  });

  const handleUpload = async () => {
    await uploadBlobs({
      signer: { account: storageAccountAddress, signAndSubmitTransaction },
      blobs: [
        {
          blobName: "example.txt",
          blobData: new Uint8Array([1, 2, 3]),
        },
      ],
      // 30 days from now in microseconds
      expirationMicros: (1000 * 60 * 60 * 24 * 30 + Date.now()) * 1000,
    });
  };

  return (
    <div>
      <p>Storage Account: {storageAccountAddress?.toString()}</p>
      <button onClick={handleUpload}>Upload</button>
    </div>
  );
}

When to Use React

Use the React entry point when you:

  • Building browser-based dApps
  • Users connect via Solana wallet extensions (Phantom, Solflare, etc.)
  • Need wallet-based signing (user approves each transaction)
  • Building React/Next.js applications

For server-side applications with direct keypair access, use the Node.js entry point instead.

Exports

The @shelby-protocol/solana-kit/react entry point exports:

ExportDescription
useStorageAccountReact hook for storage account operations
UseStorageAccountParamsType for hook parameters
UseStorageAccountResultType for hook return value
SignMessageFnType for the wallet sign message function
SignAndSubmitTransactionInputType for transaction input
SignTransactionInputType for sign-only transaction input
SubmitTransactionInputType for submit-only transaction input
NetworkNetwork configuration constants

Key Differences from Node.js

FeatureNode.js (/node)React (/react)
SigningDirect keypair signingWallet popup for user approval
Storage AccountShelbyStorageAccount classDerived via hook
EnvironmentServer-sideBrowser
Keypair AccessFull keypair (public + secret)Public key only (wallet holds secret)

Next Steps