Skip to main content

JavaScript

AppKit has support for Wagmi and Ethers v6 on Ethereum and @solana/web3.js on Solana. Choose one of these Ethereum Libraries or 'Solana' to get started.

Note

We recommend using Vite to get started with AppKit JavaScript.

Installation

npm install @web3modal/wagmi @wagmi/core @wagmi/connectors viem

Cloud Configuration

Create a new project on WalletConnect Cloud at https://cloud.walletconnect.com and obtain a new project ID.

Don't have a project ID?

Head over to WalletConnect Cloud and create a new project now!

Get startedcloud illustration

Implementation

For a quick integration you can use defaultWagmiConfig function which wraps Wagmi's createConfig function with a predefined configuration. This includes WalletConnect, Coinbase and Injected connectors, and the Blockchain API as a transport

In your main.ts file set up the following configuration.

import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi'

import { mainnet, arbitrum } from 'viem/chains'
import { reconnect } from '@wagmi/core'

// 1. Get a project ID at https://cloud.walletconnect.com
const projectId = 'YOUR_PROJECT_ID'

// 2. Create wagmiConfig
const metadata = {
name: 'AppKit',
description: 'AppKit Example',
url: 'https://web3modal.com', // origin must match your domain & subdomain.
icons: ['https://avatars.githubusercontent.com/u/37784886']
}

const chains = [mainnet, arbitrum] as const
export const config = defaultWagmiConfig({
chains,
projectId,
metadata,
})
reconnect(config)

// 3. Create modal
const modal = createWeb3Modal({
wagmiConfig: config,
projectId,
})

Trigger the modal

To open AppKit you can use our web component or build your own button with AppKit actions. In this example we are going to use the <w3m-button> component.

Web components are global html elements that don't require importing.

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

Learn more about the AppKit web components here

Smart Contract Interaction

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

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

const USDTAddress = '0x...'

const data = readContract({
address: USDTAddress,
abi: USDTAbi,
functionName: 'symbol'
})

Read more about Wagmi actions for smart contract interaction here.