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

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

npm install @shelby-protocol/react

Solana project setup

Set up your Solana project with the recommended stack:

npx create-solana-dapp

This scaffolds a project with @solana/kit and @solana/react-hooks for wallet connections.

If you're using @solana/wallet-adapter-react instead, see the adapter compatibility section below.

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 { useWalletConnection } from "@solana/react-hooks";

function MyComponent() {
  // use Solana wallet hook
  const { wallet } = useWalletConnection();

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

  // use Shelby solana-kit hook
  const { storageAccountAddress, signAndSubmitTransaction } = useStorageAccount({
    client: shelbyClient,
    wallet,
  });

  // 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>
  );
}

Using with @solana/wallet-adapter-react

If you're using the older @solana/wallet-adapter-react package, adapt the wallet to the expected shape:

import { useWallet } from "@solana/wallet-adapter-react";

function MyComponent() {
  const { publicKey, signMessage, signIn } = useWallet();

  const { storageAccountAddress, signAndSubmitTransaction } = useStorageAccount({
    client: shelbyClient,
    wallet: publicKey
      ? {
          account: { address: publicKey },
          signMessage,
          signIn,
        }
      : null,
  });

  // ...
}

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
SolanaWalletType for compatible Solana wallet
UseStorageAccountParamsType for hook parameters
UseStorageAccountResultType for hook return value
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