@0xshogun/sdk-react
TypeScript icon, indicating that this package has built-in type declarations

1.1.65 • Public • Published

Shogun SDK React Integration

Overview

The Shogun SDK React is a TypeScript library that enables cross-chain swaps and transfers between EVM chains and Solana. It provides quote fetching, transaction execution, and fee management capabilities.

Installation

npm install @0xshogun/sdk-react

or

yarn add @0xshogun/sdk-react

Features

  • Cross-chain token swaps between EVM chains and Solana
  • Quote fetching for optimal swap rates
  • Transaction execution management
  • Fee estimation and management
  • Balance tracking across chains
  • React hooks and context providers for seamless integration

Requirements

  • Node.js 16 or higher
  • TypeScript 4.5 or higher

Quick Start

import { useShogunQuote } from '@0xshogun/sdk';

...

function SwapComponent() {
    const { quote, isLoading, error } = useShogunQuote({
        fromChain: 'ethereum',
        toChain: 'solana',
        fromToken: '0x...',
        toToken: '...',
        amount: '1000000000000000000'
    });
}

React providers

'use client';
import { useSwap } from '@/store';
import { ShogunBalancesProvider, ShogunQuoteProvider, Token } from '@0xshogun/sdk';
import { useMemo } from 'react';

export const ShogunProvider = ({ children }: { children: React.ReactNode }) => {
  const {
    inputAmount,
    tokenIn,
    tokenOut,
    recipientAddress,
    slippage,
    setLatestSuggestedAutoSlippageValue,
    setInputAmount,
    dynamicSlippage // true/false, only for Solana transactions
  } = useSwap(); // Your swaps store

  const yourAddresses = {....} // Here your wallet addresses

  const affiliateWallets = useMemo(() => {
    return {
      solana: process.env.NEXT_PUBLIC_SOLANA_AFFILIATE_WALLET!, // Your affiliate wallet on solana
      evm: process.env.NEXT_PUBLIC_EVM_AFFILIATE_WALLET!, // Your affiliate wallet on evm chains
    };
  }, []);

  const api = useMemo(() => {
    return {
      key: process.env.NEXT_PUBLIC_DEXTRA_X_API_KEY!, // Dextra API keys
      url: process.env.NEXT_PUBLIC_DEXTRA_URL!, // Dextra API URL
    };
  }, []);

  return (
    <ShogunBalancesProvider apiKey={process.env.NEXT_PUBLIC_CODEX_API!}>
      <ShogunQuoteProvider
        swap={{
          tokenIn: tokenIn as Token,
          tokenOut: tokenOut as Token,
          setLatestSuggestedAutoSlippageValue,
          inputAmount,
          setInputAmount,
          recipientAddress,
          slippage,
        }}
        system={{
          api,
          systemFeePercent: 0.01,
          userEVMAddress: yourAddresses?.turnKeyEVMAddress as string,
          userSolanaAddress: yourAddresses?.turnkeySolanaAddress as string,
          affiliateWallets,
        }}
      >
        {children}
      </ShogunQuoteProvider>
    </ShogunBalancesProvider>
  );
};

Development

Install dependencies

npm install

Build the package

npm run build

Run tests

npm test

Format code

npm run format

Lint code

npm run lint

Contributing Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

Package Sidebar

Install

npm i @0xshogun/sdk-react

Weekly Downloads

32

Version

1.1.65

License

ISC

Unpacked Size

225 kB

Total Files

44

Last publish

Collaborators

  • ebrahimshogun
  • garageinc