You can switch chains between different EVM networks (see Supported Chains for the enabled network list). By default, you use the Ethereum mainnet.
//interface
switchChain(chainId: string): Promise<void>
getChainId(): number | string
const chainId = '1'
// react
const current = await ethereumProvider.getChainId();
const res = await ethereumProvider.switchChain(chainId);
// pure js
const current = await window.tomo_ethereum.getChainId();
const res = await window.tomo_ethereum.switchChain(chainId);
Get the EVM address
The EVM address from the wallet state or provider.
import { useTomo, getWalletState } from '@tomo-inc/tomo-web-sdk';
const { walletState, providers } = useTomo()
// get from wallet state
const address = walletState.address
// or get from provider
const address = await providers.ethereumProvider.request({ method: "eth_accounts" })?.[0]
/** pure js */
// get from wallet state
const address = getWalletState().address
// or get from provider
const address = await window.tomo_ethereum.request({ method: "eth_accounts" })?.[0]
Provider Functions
providers.ethereumProvider exposes three functions for sending requests to the user's wallet:
Signing a Message
It uses the Ethereum provider to sign a plaintext offchain message, which returns the message's signature with the message header. We also provide a shortcut for sign type data where the msg is a json string of the data.
You can also send the transaction directly through this sendTransaction method. The return value is the transaction signature if signed and sent correctly.