Skip to main content

React Installation

The Mina SDK provides first-class React support with hooks and a context provider for seamless integration into your React applications.

Installation

Install the SDK along with its peer dependencies.
npm install @siphoyawe/mina-sdk viem react react-dom

Requirements

DependencyVersionPurpose
react^18.0.0React library
react-dom^18.0.0React DOM renderer
viem^2.0.0Ethereum interactions

Import Path

React-specific exports are available from a dedicated subpath:
// React hooks and provider
import {
  MinaProvider,
  useMina,
  useQuote,
  useTokenBalance,
  useTransactionStatus
} from '@siphoyawe/mina-sdk/react';

// Core SDK (also available)
import { Mina, getChains, getTokens } from '@siphoyawe/mina-sdk';
The /react subpath includes client-side only code. Always import React hooks from @siphoyawe/mina-sdk/react, not from the main entry point.

Framework Setup

The SDK requires client-side rendering. Mark your provider component with 'use client':
app/providers.tsx
'use client';

import { MinaProvider } from '@siphoyawe/mina-sdk/react';

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <MinaProvider config={{ integrator: 'my-app' }}>
      {children}
    </MinaProvider>
  );
}
Then use in your root layout:
app/layout.tsx
import { Providers } from './providers';

export default function RootLayout({
  children
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}
The 'use client' directive is required for any component using Mina hooks. Without it, Next.js will attempt server-side rendering which will fail.

TypeScript Configuration

Ensure your tsconfig.json supports the SDK:
tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "bundler",
    "target": "ES2020",
    "lib": ["ES2020", "DOM"],
    "jsx": "react-jsx"
  }
}

Verifying Setup

Create a simple component to verify the SDK is working:
components/SDKStatus.tsx
'use client';

import { useMina } from '@siphoyawe/mina-sdk/react';

export function SDKStatus() {
  const { mina, isReady, error } = useMina();

  if (error) {
    return <div>SDK Error: {error.message}</div>;
  }

  if (!isReady) {
    return <div>Initializing SDK...</div>;
  }

  return <div>SDK Ready</div>;
}

Available Exports

The /react subpath exports:
ExportTypeDescription
MinaProviderComponentContext provider for SDK instance
useMinaHookAccess SDK instance and status
useQuoteHookFetch bridge quotes with debouncing
useTokenBalanceHookTrack token balances with auto-refresh
useTransactionStatusHookPoll transaction status
Additionally, commonly used types are re-exported for convenience:
import type {
  MinaConfig,
  Chain,
  Token,
  Quote,
  QuoteParams,
  Balance,
  ExecutionResult,
  TransactionStatus,
} from '@siphoyawe/mina-sdk/react';

Next Steps

MinaProvider

Configure and set up the provider

useMina Hook

Access the SDK instance