Getting Started

Setting up the Torque in a React application

Requirements

  • React 18 or higher

  • A Solana wallet adapter implementation

Installation

npm install @torque-labs/react @torque-labs/sdk --save

Setup

TorqueProvider

To use the Torque React SDK, you need to wrap your application with the TorqueProvider component. This provider gives access to the Torque SDK instance and various hooks for interacting with the Torque platform.

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

import { TorqueProvider } from '@torque-labs/react';

function Provider({ children }: PropsWithChildren) {
  const { wallet } = useWallet();

  const torqueOptions = {
    apiUrl: "https://server.torque.so", 
    rpcUrl: "<solana rpc>", // Your Solana RPC URL
    authDomain: "your-app-domain.com", // Used for Sign-In-With-Solana (SIWS)   
  }

  return (
    <TorqueProvider options={torqueOptions} wallet={wallet}>
      {children}
    </TorqueProvider>
  );
}

Required Props

The TorqueProvider accepts the following props:

  • wallet: The wallet adapter instance from libraries like @solana/wallet-adapter-react.

  • options: Configuration options for the Torque SDK:

    • apiUrl: The URL for the Torque API server.

    • rpcUrl: The RPC URL for the Solana network.

    • authDomain: The domain to display when signing in with Solana.

NOTE: The provider will automatically request the user for a signature to authenticate them with the Torque API. This allow's to make requests directly using the react library.

TorqueProvider Context

You can access the Torque SDK context directly using the useTorque hook:

The torque instance above can be used to directly query the Torque API. The torque SDK will be initialized for the current user once they are authenticated.

Authentication

If authenticate fails, it can be triggered manually to authenticate a user with the Torque SDK:

Advanced Usage

Using Transaction-Based Authentication

For hardware wallets like Ledger:

Last updated