Skip to main content

HTML

caution

This documentation is for Web3Modal v3 which is currently in Beta. You can find Web3Modal v2 documentation here

With Web3Modal HTML we work with the @wagmi/core library which contains everything you need to start working with Ethereum. You can sign messages, interact with smart contracts, and much more.

Don't have a project ID?

Head over to WalletConnect Cloud and create a New Project now!

Get startedcloud illustration

Installation​

Yo can install Web3Modal SDK by using a package manager like npm or with CDN imports.

Choose your preferred package manager

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

Implementation​

You can start Web3Modal configuration using either default or custom mode.

Default mode will implement WalletConnect, Browser Wallets (injected) and Coinbase options in addition to Wagmi's public provider and WalletConnect's provider.

Start by importing Web3Modal, defaultWagmiConfig and wagmi packages, then create wagmiConfig using defaultWagmiConfig function as shown below. Finally, pass wagmiConfig to the Web3Modal class.

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

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

// 1. Define constants
const projectId = 'YOUR_PROJECT_ID'

// 2. Create wagmiConfig
const chains = [mainnet, arbitrum]
const wagmiConfig = defaultWagmiConfig({ chains, projectId, appName: 'Web3Modal' })

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

Trigger the modal​

To open Web3Modal you can use our web components or build your own logic with Web3Modal actions

You can use default web components to open the modal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML Example</title>
</head>
<body>
<w3m-button />
<script type="module" src="main.js"></script>
</body>
</html>

Learn more about the Web3Modal web components here

note

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

Use wagmi Actions​

wagmi provides everything you'll need to start working with accounts, contracts, chains and much more.

import { getAccount, writeContract, disconnect, watchAccount } from '@wagmi/core'