Integrate AGW into an existing React application using the steps below, or

watch the video tutorial for a step-by-step walkthrough.

1. Install Abstract Global Wallet

Install the required dependencies:

npm install @abstract-foundation/agw-react @abstract-foundation/agw-client wagmi [email protected] @tanstack/react-query

2. Setup the AbstractWalletProvider

Wrap your application in the AbstractWalletProvider component to enable the use of the package’s hooks and components throughout your application.

import { AbstractWalletProvider } from "@abstract-foundation/agw-react";

const config = {
  testnet: true, // Required
  // Optionally, provide your own RPC URL (learn more: https://viem.sh/docs/clients/transports/http.html)
  // transport: http("https://your.abstract.node.example.com/rpc") // Optional
};

const App = () => {
  return (
    <AbstractWalletProvider config={config}>
      {/* Your application components */}
    </AbstractWalletProvider>
  );
};

Next.js App Router: If you are using Next.js App Router, create a new component and add the use client directive at the top of your file (see example) and wrap your application in this component (see example).

The AbstractWalletProvider wraps your application in both the WagmiProvider and QueryClientProvider, meaning you can use the hooks and features of these libraries within your application.

3. Login with AGW

With the provider setup, prompt users to sign in to your application with their Abstract Global Wallet using the useLoginWithAbstract hook.

import { useLoginWithAbstract } from "@abstract-foundation/agw-react";

export default function SignIn() {
  // login function to prompt the user to sign in with AGW.
  const { login } = useLoginWithAbstract();

  return <button onClick={login}>Connect with AGW</button>;
}

4. Use the Wallet

With the AGW connected, prompt the user to approve sending transactions from their wallet.