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/sdkFor simplicity, also install the Shelby react package for react hooks helpers
npm install @shelby-protocol/reactSolana 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-walletsOr simply set up your project with
npx create-solana-dappUsage
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:
| Export | Description |
|---|---|
useStorageAccount | React hook for storage account operations |
UseStorageAccountParams | Type for hook parameters |
UseStorageAccountResult | Type for hook return value |
SignMessageFn | Type for the wallet sign message function |
SignAndSubmitTransactionInput | Type for transaction input |
SignTransactionInput | Type for sign-only transaction input |
SubmitTransactionInput | Type for submit-only transaction input |
Network | Network configuration constants |
Key Differences from Node.js
| Feature | Node.js (/node) | React (/react) |
|---|---|---|
| Signing | Direct keypair signing | Wallet popup for user approval |
| Storage Account | ShelbyStorageAccount class | Derived via hook |
| Environment | Server-side | Browser |
| Keypair Access | Full keypair (public + secret) | Public key only (wallet holds secret) |
Next Steps
useStorageAccount Hook
Complete reference for the storage account hook
Upload a File
Step-by-step guide with React examples