Tomo Docs
Tomo Docs
  • Overview
    • Introducing Tomo
    • Tomo's Key Management
  • Tomo SDK
    • TomoEVMKit
      • Quick Start
      • Use with Ethers.js
      • Migration from RainbowKit
      • Migration from Blocknative
      • Internal Wallet Services
      • Supported Chains
    • Tomo Web SDK
      • Quick Start
      • Solana Provider
      • EVM Provider
      • Bitcoin Provider
      • Tron Provider
      • Movement Provider
      • Sui Provider
      • Internal Wallet Services
    • Tomo Telegram SDK
      • Quick Start
      • Wallet Provider
        • EVM Provider
        • Solana Provider
        • Sui Provider (Beta)
        • TON Provider
      • Partners
    • Tomo Enterprise SDK
      • For Babylon
        • Install the SDK
        • Tomo Wallet Provider
        • Bitcoin Provider
        • Cosmos Provider
        • Multiple Connection Mode
        • Integrate Extension Wallet
          • Submit Wallet PR
          • Extend the SDK
          • Q & A
        • Integrate Mobile Wallet
  • TOMO WALLET
    • Tomo Wallets
    • Mobile Wallet
      • Tomo Keys
        • Bonding Curve Explained
        • How to: Tomo Keys
      • TomoID
        • How to: TomoID
        • How to: Connect Instagram
      • Tomo Socials
      • Tomo Android App
      • Tomo iOS App
    • Extension Wallet
      • Developer Manual
        • EVM Integration
        • Bitcoin Integration
      • Example of User Flows
        • Claiming Signet BTC
        • Staking at Testnet
      • Install Link
    • Telegram Wallet
      • Quick Start
      • Chains/Networks
      • User Manual
        • Account Security
        • Gift feature
        • FAQ
        • Transaction
        • Swap
  • ABOUT US
    • Brand Assets
    • Privacy Policy
Powered by GitBook
On this page
  • Switch Chain ID
  • Get the EVM address
  • Provider Functions
  • Signing a Message
  • Send Transaction
  • Requests
  1. Tomo SDK
  2. Tomo Web SDK

EVM Provider

After setting up your wallet, you can access the EVM provider:

import { useTomo, getWalletState } from '@tomo-inc/tomo-web-sdk';
// react
const { providers } = useTomo()
const { ethereumProvider } = providers;

// pure js
const ethereumProvider = window.tomo_ethereum

Switch Chain ID

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.

// interface
signMessage(msg: string, address:string): Promise<string>
signTypedData(address: string, msg: string): Promise<string>

 // react
 const personalSignResult = await ethereumProvider.request(msg, address);
 
 // pure js
 const personalSignResult = await window.tomo_ethereum.request(msg, address);

Send Transaction

You can also send the transaction directly through this sendTransaction method. The return value is the transaction signature if signed and sent correctly.

// interface
sendTransaction(params: EvmTxParams): Promise<any>

interface EvmTxParams {
  from: string;
  to: string;
  value: string;
  gasPrice?: string;
  gasLimit?: string;
  maxFeePerGas?: string;
  maxPriorityFeePerGas?: string;
  data?: string;
}

const Tx= {
    from: address,
    to: address,
    value: "0x5af3107a4000",
    nonce: "0x0",
  },
// react
const res = await ethereumProvider.sendTransaction(Tx);

// pure js
const res = await window.tomo_ethereum.sendTransaction(Tx);

Requests

//interface
request<Result = any, Params = any>(request: RequestArguments<Params>, context?: any): Promise<Result>


interface RequestArguments<T = any> {
    method: string;
    params?: T;
    id?: number;
}

const walletActions = {
  eth_requestAccounts: "eth_requestAccounts",
  eth_accounts: "eth_accounts",
  wallet_watchAsset: "wallet_watchAsset",
  eth_addEthereumChain: "eth_addEthereumChain",
  eth_switchEthereumChain: "eth_switchEthereumChain",
  wallet_switchEthereumChain: "wallet_switchEthereumChain",
  personal_sign: "personal_sign",
  eth_signTypedData_v4: "eth_signTypedData_v4",
  wallet_getPermissions: "wallet_getPermissions",
  wallet_requestPermissions: "wallet_requestPermissions",
  eth_sendTransaction: "eth_sendTransaction",
  eth_sendRawTransaction: "eth_sendRawTransaction",
  personal_ecRecover: "personal_ecRecover",
  eth_swapTransaction: "eth_swapTransaction",
  eth_approveTransaction: "eth_approveTransaction",
  eth_chainId: "eth_chainId",
};


const data = {
  method: "eth_sendTransaction",
  params: [
    {
      from: address,
      to: address,
      value: "0x5af3107a4000",
      nonce: "0x0",
    },
  ],
}
// react
const res = await ethereumProvider.request(data);

// pure js
const res = await window.tomo_ethereum.request(data);
PreviousSolana ProviderNextBitcoin Provider

Last updated 24 days ago

We also support the wallet JSON RPC API for wallet actions

standard