Skip to main content

Actions

Open and close the modal​

const modal = createWeb3Modal({ wagmiConfig, projectId })

modal.open()

modal.close()

You can also select the modal's view when calling the open function

modal.open({ view: 'Account' })

List of views you can select

VariableDescription
ConnectPrincipal view of the modal - default view when disconnected
AccountUser profile - default view when connected
AllWalletsShows the list of all available wallets
NetworksList of available networks - you can select and target a specific network before connecting
WhatIsANetwork"What is a network" onboarding view
WhatIsAWallet"What is a wallet" onboarding view

Disconnect​

Disconnect currently connected account.

modal.disconnect()

Get the current value of the modal's state

const modal = createWeb3Modal({ wagmiConfig, projectId })

const { open, selectedNetworkId } = modal.getState()

The modal state is an object of two properties:

PropertyDescriptionType
openOpen state will be true when the modal is open and false when closed.boolean
selectedNetworkIdThe current chain id selected by the usernumber

You can also subscribe to the modal's state changes.

const modal = createWeb3Modal({ wagmiConfig, projectId })

modal.subscribeState(newState => console.log(newState))

ThemeMode​

Set the themeMode after creating the modal

const modal = createWeb3Modal({ wagmiConfig, projectId })

modal.setThemeMode('dark')

Get the current themeMode value by calling the getThemeMode function

const modal = createWeb3Modal({ wagmiConfig, projectId })

const themeMode = modal.getThemeMode()

themeVariables​

Set the themeVariables after creating the modal

const modal = createWeb3Modal({ wagmiConfig, projectId })

modal.setThemeVariables({ ... })

Get the current themeVariables value by calling the getThemeVariables function

const modal = createWeb3Modal({ wagmiConfig, projectId })

const themeMode = modal.getThemeVariables()

Subscribe to theme changes​

const unsubscribe = modal.subscribeTheme(newTheme => console.log(newTheme))

Track modal events​

modal.getEvent() // get last event
modal.subscribeEvents(event => console.log(event)) // subscribe to events

Ethereum Library​

You can use Wagmi actions to sign messages, interact with smart contracts, and much more.

getAccount​

Action for accessing account data and connection status.

import { getAccount } from '@wagmi/core'

const account = getAccount()

signMessage​

Action for signing messages with connected account.

import { signMessage } from '@wagmi/core'

const signature = await signMessage({
message: 'gm wagmi frens'
})