For the complete documentation index, see llms.txt. This page is also available as Markdown.

EVM (EIP-155)

TrustConnect provides React hooks for interacting with Ethereum and EVM-compatible chains. The EIP-155 package is built on top of Viem and uses Viem actions for read and write operations.

Installation

pnpm add @trustwallet/connect-eip155-react

Peer dependencies:

pnpm add @tanstack/react-query viem

Setup

Configure EVM chains using createEIP155:

import { mainnet, polygon } from 'viem/chains'
import { createEIP155 } from '@trustwallet/connect-eip155-react'

const eip155 = createEIP155({
    chains: [mainnet, polygon],
})

Custom RPC URLs

You can configure custom RPC endpoints per chain. Since Viem doesn't follow CAIP-2, use formatChainId to convert chain IDs:

import { mainnet } from 'viem/chains'
import { formatChainId, createEIP155 } from '@trustwallet/connect-eip155-react'

const caipMainnetId = formatChainId(mainnet.id)

const eip155 = createEIP155({
    chains: [mainnet],
    rpcUrls: {
        [caipMainnetId]: ['https://rpc-node.com'],
    },
})

Read operations

useEIP155Query

Use useEIP155Query for read-only operations with any Viem public action:

Important: Always pass queryOptions.enabled: isConnected to prevent the query from running before a wallet is connected. Without this, the query will fail with a "Transport is undefined" error because no RPC client exists yet.

Write operations

useSignMessage

Sign messages with the connected EVM wallet:

useWriteContract

Call smart contract functions that modify state. This hook handles chain switching automatically and waits for transaction confirmation via waitForTransactionReceipt.

Note: You can disable automatic chain switching by setting autoSwitchChain to false.

useSendTransaction

Send native token transfers. Like useWriteContract, this hook handles chain switching and waits for confirmation automatically.

useEIP155Mutation

Use useEIP155Mutation for any Viem wallet action not covered by the higher-level hooks:

Last updated

Was this helpful?