Skip to main content

Actions

caution

This documentation is for Web3Modal v2. You can find Web3Modal v3 docs here

openModal

Programmatically open the modal. Optionally, override default route to open.

Example

await web3modal.openModal()

Reference

openModal: (options?: Options) => Promise<void>
// Options that can be passed to override default route
interface Options {
route?: 'Account' | 'ConnectWallet' | 'Help' | 'SelectNetwork'
}

closeModal

Programmatically close the modal.

Example

web3modal.closeModal()

Reference

closeModal: () => void

subscribeModal

Subscribe or unsubscribe from modal's state.

Example

const unsubscribe = web3modal.subscribeModal(newState => console.log(newState))
unsubscribe()

Reference

subscribeModal: (callback: (newState: Object) => void) => () => void

setDefaultChain

Sets the default chain before the user connects.

Example

web3modal.setDefaultChain(polygon)

Reference

setDefaultChain: (chain: WagmiChain) => void

setTheme

Programmatically set or update theme options for themeVariables and themeMode.

Example

web3modal.setTheme({
themeMode: 'dark',
themeVariables: {
'--w3m-font-family': 'Roboto, sans-serif',
'--w3m-accent-color': '#F5841F'
// ...
}
})

Reference

setTheme: (theme: Theme) => void
interface Theme {
themeMode: 'dark' | 'light'
themeVariables: Object
}

Wagmi Actions

Other actions like getAccount, getContract and many more are available from wagmi.