Skip to content

Latest commit

 

History

History
511 lines (358 loc) · 12 KB

File metadata and controls

511 lines (358 loc) · 12 KB
title Installation

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

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

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

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

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

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

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

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

import CoreImplementation from '/snippets/appkit/javascript/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.

We recommend using [Vite](https://vitejs.dev/guide/#scaffolding-your-first-vite-project) to get started with AppKit JavaScript.

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

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
yarn add @reown/appkit @reown/appkit-adapter-wagmi wagmi@2.18.0 viem
bun add @reown/appkit @reown/appkit-adapter-wagmi wagmi@2.18.0 viem
pnpm add @reown/appkit @reown/appkit-adapter-wagmi wagmi@2.18.0 viem
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

Check the JavaScript wagmi example Check the JavaScript 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 JavaScript Solana example Check the JavaScript Bitcoin example Check the JavaScript TON example Check the JavaScript AppKit Core example for Sui and Stacks

Trigger the modal

To open AppKit you can use our web component or build your own button with AppKit actions.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>HTML AppKit Example</title>
  </head>
  <body>
    <appkit-button />
    <script type="module" src="main.js"></script>
  </body>
</html>

You can trigger the modal by calling the open function from the modal instance.

const modal = createAppKit({
  adapters: [wagmiAdapter],
  networks: [mainnet, arbitrum],
  projectId
})

modal.open()

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

<script>
  let session = null

  async function handleConnect() {
    // universalConnector is the universal connector instance from the implementation section
    if (!universalConnector) {
      return
    }

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

  async function handleDisconnect() {
    if (!universalConnector) {
      return
    }
    await universalConnector.disconnect()
    session = null
  }

  document.getElementById('open-connect-modal').addEventListener('click', handleConnect)
  document.getElementById('disconnect').addEventListener('click', handleDisconnect)
</script>

<div>
  <button id="open-connect-modal">Open AppKit Core</button>
  <button id="disconnect">Disconnect</button>
</div>

Blockchain Interaction

You need to install @wagmi/core to interact with smart contracts:
npm install @wagmi/core
yarn add @wagmi/core
bun a @wagmi/core
pnpm add @wagmi/core

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

For this use case, we need to import the wagmiConfigfrom our AppKit WagmiAdapter configuration.

import { readContract } from '@wagmi/core'
import { USDTAbi } from '../abi/USDTAbi'

const USDTAddress = '0x...'

const data = readContract(wagmiConfig, {
  address: USDTAddress,
  abi: USDTAbi,
  functionName: 'totalSupply',
  args: []
})

Read more about Wagmi actions for smart contract interaction here.

Ethers can help us interact with wallets and smart contracts:

import { BrowserProvider, Contract, parseEther } from 'ethers'

const provider = await modal.subscribeProviders(state => {
  return state['eip155']
})

const addressFrom = await modal.subscribeAccount(state => {
  return state
})

if (!provider) throw Error('No provider found')
if (!addressFrom) throw Error('No address found')

function sendTransaction() {
  const tx = {
    from: addressFrom,
    to: '0x...', // any address
    value: parseEther('0.0001')
  }
  const ethersProvider = new BrowserProvider(provider)
  const signer = await ethersProvider.getSigner()
  const tx = await signer.sendTransaction(tx)
  console.log('transaction:', tx)
}

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.