Skip to content

Latest commit

 

History

History
572 lines (408 loc) · 13.8 KB

File metadata and controls

572 lines (408 loc) · 13.8 KB
title Installation

import CloudBanner from '/snippets/cloud-banner.mdx'

import WagmiImplementation from '/snippets/appkit/react/wagmi/about/implementation.mdx'

import Ethers5Implementation from '/snippets/appkit/react/ethers5/implementation.mdx'

import EthersImplementation from '/snippets/appkit/react/ethers/about/implementation.mdx'

import SolanaImplementation from '/snippets/appkit/react/solana/about/implementation.mdx' import SolanaPrograms from '/snippets/appkit/react/solana/about/programs.mdx'

import BitcoinImplementation from '/snippets/appkit/react/bitcoin/about/implementation.mdx'

import TonImplementation from '/snippets/appkit/react/ton/about/implementation.mdx'

import TronImplementation from '/snippets/appkit/react/tron/about/implementation.mdx'

import CoreImplementation from '/snippets/appkit/react/core/about/implementation.mdx'

AppKit provides seamless integration with multiple blockchain ecosystems. It supports Wagmi and Ethers v6 on Ethereum, @solana/web3.js on Solana, as well as Bitcoin, TON, TRON and other networks.

Installation

Try installing AppKit Skills to get AI-assisted guidance. Your AI coding assistant can help you set up, build, and debug your AppKit integration.

To install AppKit Skills, run the following command in your terminal:

npx skills add https://github.com/reown-com/skills --skill appkit --agent '*'

After installation, you can ask your AI assistant for help with AppKit setup, implementation, and troubleshooting.

Custom Installation

If you are setting up your React app, please **do not use** `npx create-react-app`, as it has been deprecated. Using it may cause dependency issues. Instead, please use [Vite](https://vitejs.dev/guide/#scaffolding-your-first-vite-project) to create your React app. You can set it up by running `npm create vite@latest`. AppKit is only compatible with wagmi 2.x. Ensure you are using a compatible version (e.g., `wagmi@2.18.0`).
npm install @reown/appkit @reown/appkit-adapter-wagmi wagmi@2.18.0 viem @tanstack/react-query
yarn add @reown/appkit @reown/appkit-adapter-wagmi wagmi@2.18.0 viem @tanstack/react-query
bun add @reown/appkit @reown/appkit-adapter-wagmi wagmi@2.18.0 viem @tanstack/react-query
pnpm add @reown/appkit @reown/appkit-adapter-wagmi wagmi@2.18.0 viem @tanstack/react-query
npm install @reown/appkit @reown/appkit-adapter-ethers5 ethers@5.7.2
yarn add @reown/appkit @reown/appkit-adapter-ethers5 ethers@5.7.2
bun add @reown/appkit @reown/appkit-adapter-ethers5 ethers@5.7.2
pnpm add @reown/appkit @reown/appkit-adapter-ethers5 ethers@5.7.2
npm install @reown/appkit @reown/appkit-adapter-ethers ethers
yarn add @reown/appkit @reown/appkit-adapter-ethers ethers
bun add @reown/appkit @reown/appkit-adapter-ethers ethers
pnpm add @reown/appkit @reown/appkit-adapter-ethers ethers
npm install @reown/appkit @reown/appkit-adapter-solana
yarn add @reown/appkit @reown/appkit-adapter-solana
bun add @reown/appkit @reown/appkit-adapter-solana
pnpm add @reown/appkit @reown/appkit-adapter-solana
npm install @reown/appkit @reown/appkit-adapter-bitcoin
yarn add @reown/appkit @reown/appkit-adapter-bitcoin
bun add @reown/appkit @reown/appkit-adapter-bitcoin
pnpm add @reown/appkit @reown/appkit-adapter-bitcoin
npm install @reown/appkit @reown/appkit-adapter-ton
yarn add @reown/appkit @reown/appkit-adapter-ton
bun add @reown/appkit @reown/appkit-adapter-ton
pnpm add @reown/appkit @reown/appkit-adapter-ton
npm install @reown/appkit @reown/appkit-adapter-tron
yarn add @reown/appkit @reown/appkit-adapter-tron
bun add @reown/appkit @reown/appkit-adapter-tron
pnpm add @reown/appkit @reown/appkit-adapter-tron
npm install @reown/appkit @reown/appkit-universal-connector @reown/appkit-common ethers
yarn add @reown/appkit @reown/appkit-universal-connector @reown/appkit-common ethers
bun add @reown/appkit @reown/appkit-universal-connector @reown/appkit-common ethers
pnpm add @reown/appkit @reown/appkit-universal-connector @reown/appkit-common ethers

Cloud Configuration

Create a new project on Reown Dashboard and obtain a new project ID.

Implementation

AppKit providers two different approaches on React to initialize it.

Use AppKitProvider React component for easy integration in React applications. This component wraps your app and provides the AppKit context to all child components.

import { AppKitProvider } from '@reown/appkit/react'

function App() {
  return (
    <AppKitProvider
      projectId="YOUR_PROJECT_ID"
      networks={
        [
          /* Your Networks */
        ]
      }
    >
      {/* Your App */}
    </AppKitProvider>
  )
}

Use createAppKit method from @reown/appkit/react to initialize AppKit instance and call it on the root of your application with desired parameters depending on your use case.

import { createAppKit } from '@reown/appkit/react'

createAppKit({
  networks: [
    /* Your networks */
  ],
  adapters: [
    /* Your adapters */
  ],
  ...appKitProps
})

function App() {
  return <>{children}</>
}

Adapter Configuration

Check the React wagmi example Check the React ethers v5 example Check the React ethers example MetaMask does not currently support WalletConnect connections on Solana. The MetaMask team is working on adding this feature. In the meantime, we recommend using other wallets that support Solana. You can find the complete list of supported wallets on [WalletGuide](https://walletguide.walletconnect.network/). Check the React Solana example Check the React Bitcoin example Check the React AppKit Core example for Sui

Trigger the modal

To open AppKit you can use our React components or build your own button with AppKit hooks.

import { AppKitButton } from '@reown/appkit/react'

export default function ConnectButton() {
  return <AppKitButton />
}
import { useAppKit } from '@reown/appkit/react'

export default function ConnectButton() {
  const { open } = useAppKit()

  return (
    <>
      <button onClick={() => open()}>Open Connect Modal</button>
      <button onClick={() => open({ view: 'Networks' })}>Open Network Modal</button>
    </>
  )
}

To open AppKit Core you need to call the connect function from the Universal Connector.

// get the session from the universal connector
const handleConnect = async () => {
  if (!universalConnector) {
    return
  }

  const { session: providerSession } = await universalConnector.connect()
  setSession(providerSession)
}

// disconnect the universal connector
const handleDisconnect = async () => {
  if (!universalConnector) {
    return
  }
  await universalConnector.disconnect()
  setSession(null)
}

...

return (
  <div>
    <button onClick={handleConnect}>Open AppKit Core</button>
    <button onClick={handleDisconnect}>Disconnect</button>
  </div>
)

Smart Contract Interaction

Wagmi hooks can help us interact with wallets and smart contracts:

import { useReadContract } from 'wagmi'
import { USDTAbi } from '../abi/USDTAbi'

const USDTAddress = '0x...'

function App() {
  const result = useReadContract({
    abi: USDTAbi,
    address: USDTAddress,
    functionName: 'totalSupply'
  })
}

Read more about Wagmi hooks for smart contract interaction here.

Ethers can help us interact with wallets and smart contracts:

import { useAppKitProvider, useAppKitAccount } from '@reown/appkit/react'
import { BrowserProvider, Contract, formatUnits } from 'ethers'

const USDTAddress = '0x617f3112bf5397D0467D315cC709EF968D9ba546'

// The ERC-20 Contract ABI, which is a common contract interface
// for tokens (this is the Human-Readable ABI format)
const USDTAbi = [
  'function name() view returns (string)',
  'function symbol() view returns (string)',
  'function balanceOf(address) view returns (uint)',
  'function transfer(address to, uint amount)',
  'event Transfer(address indexed from, address indexed to, uint amount)'
]

function Components() {
  const { address, isConnected } = useAppKitAccount()
  const { walletProvider } = useAppKitProvider('eip155')

  async function getBalance() {
    if (!isConnected) throw Error('User disconnected')

    const ethersProvider = new BrowserProvider(walletProvider)
    const signer = await ethersProvider.getSigner()
    // The Contract object
    const USDTContract = new Contract(USDTAddress, USDTAbi, signer)
    const USDTBalance = await USDTContract.balanceOf(address)

    console.log(formatUnits(USDTBalance, 18))
  }

  return <button onClick={getBalance}>Get User Balance</button>
}

Video Tutorial

<iframe style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', maxWidth: '560px', margin: '0 auto' }} src="https://www.youtube.com/embed/lxTGqXh7LiA?si=1MQMbtqQtM6KSfE0" title="YouTube video player" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerPolicy="strict-origin-when-cross-origin" allowFullScreen />

Alternative Installation

If you are starting from scratch, you can use the following methods to set up your project with Reown AppKit.

AppKit Skills provide AI-powered assistance for building with Reown AppKit. Once installed, your AI coding assistant can help you set up, build, and debug your AppKit integration.

To install AppKit Skills, run the following command in your terminal:

npx skills add https://github.com/reown-com/skills --skill appkit --agent '*'

After installation, you can ask your AI assistant for help with AppKit setup, implementation, and troubleshooting.

Reown offers a dedicated CLI to set up a minimal version of AppKit in the easiest and quickest way possible.

To do this, please run the command below.

npx @reown/appkit-cli

After running the command, you will be prompted to confirm the installation of the CLI. Upon your confirmation, the CLI will request the following details:

  1. Project Name: Enter the name for your project.
  2. Framework: Select your preferred framework or library. Currently, you have three options: React, Next.js, and Vue.
  3. Network-Specific libraries: Choose whether you want to install Wagmi, Ethers, Solana, or Multichain (EVM + Solana).

After providing the project name and selecting your preferences, the CLI will install a minimal example of AppKit with your preferred blockchain library. The example will be pre-configured with a projectId that will only work on localhost.

To fully configure your project, please obtain a projectId from the Reown Dashboard and update your project accordingly.

Refer to this section for more information.