EIP-1193 Provider

Wagmi SDK — EIP-1193 Provider

When using @nexus-cross/crossx-sdk-wagmi, the EIP-1193 provider is managed automatically by wagmi. You typically interact with it through wagmi hooks rather than directly.

How it works

The crossxConnector implements wagmi's Connector interface, which internally provides an EIP-1193 provider. When you use wagmi hooks like useSendTransaction or useSignMessage, they route requests through this provider automatically.

wagmi hooks → crossxConnector → CROSSx EIP-1193 Provider → CROSSx Gateway

Using wagmi hooks (recommended)

In most cases, you don't need to access the provider directly:

import { useSignMessage, useSendTransaction } from 'wagmi'
import { parseEther } from 'viem'

function WagmiExample() {
  const { signMessage } = useSignMessage()
  const { sendTransaction } = useSendTransaction()

  return (
    <div>
      <button onClick={() => signMessage({ message: 'Hello CROSSx' })}>
        Sign Message
      </button>
      <button onClick={() => sendTransaction({
        to: '0xRecipient...',
        value: parseEther('0.1'),
      })}>
        Send Transaction
      </button>
    </div>
  )
}

Direct provider access via useWalletClient

For advanced use cases, access the viem wallet client (which wraps the provider):

import { useWalletClient, usePublicClient } from 'wagmi'
import { parseEther, parseUnits } from 'viem'

function DirectProviderAccess() {
  const { data: walletClient } = useWalletClient()
  const publicClient = usePublicClient()

  const handleContractRead = async () => {
    if (!publicClient) return

    const balance = await publicClient.readContract({
      address: '0xTokenAddress',
      abi: erc20Abi,
      functionName: 'balanceOf',
      args: ['0xYourAddress'],
    })
    console.log('Token balance:', balance)
  }

  const handleContractWrite = async () => {
    if (!walletClient) return

    const hash = await walletClient.writeContract({
      address: '0xTokenAddress',
      abi: erc20Abi,
      functionName: 'transfer',
      args: ['0xRecipient', parseUnits('100', 18)],
    })
    console.log('TX:', hash)
  }

  return (
    <div>
      <button onClick={handleContractRead}>Read Contract</button>
      <button onClick={handleContractWrite}>Write Contract</button>
    </div>
  )
}

Raw provider access

If you need the raw EIP-1193 provider (rare):

import { useConnectorClient } from 'wagmi'

function RawProvider() {
  const { data: client } = useConnectorClient()

  const handleRaw = async () => {
    if (!client) return

    const provider = client.transport
    const blockNumber = await client.request({
      method: 'eth_blockNumber',
    })
    console.log('Block:', blockNumber)
  }

  return <button onClick={handleRaw}>Raw RPC Call</button>
}

Contract interaction with wagmi hooks

wagmi provides dedicated hooks for contract interaction:

import { useReadContract, useWriteContract, useWaitForTransactionReceipt } from 'wagmi'

const erc20Abi = [/* ... */] as const

function TokenTransfer() {
  // Read
  const { data: balance } = useReadContract({
    address: '0xTokenAddress',
    abi: erc20Abi,
    functionName: 'balanceOf',
    args: ['0xYourAddress'],
  })

  // Write
  const { writeContract, data: hash } = useWriteContract()
  const { isSuccess } = useWaitForTransactionReceipt({ hash })

  const handleTransfer = () => {
    writeContract({
      address: '0xTokenAddress',
      abi: erc20Abi,
      functionName: 'transfer',
      args: ['0xRecipient', parseUnits('100', 18)],
    })
  }

  return (
    <div>
      <p>Balance: {balance?.toString()}</p>
      <button onClick={handleTransfer}>Transfer</button>
      {isSuccess && <p>Transfer confirmed!</p>}
    </div>
  )
}

When to use which approach

ApproachUse when
wagmi hooks (useSendTransaction, etc.)Standard operations — recommended for most cases
useWalletClient / usePublicClientCustom viem operations not covered by hooks
Raw provider accessRare, low-level RPC calls not supported by viem

Notes

  • The CROSSx provider is fully compatible with wagmi's connector interface.
  • Signing and transaction methods always display a user confirmation modal, regardless of access method.
  • For a detailed list of supported RPC methods, see Core SDK — EIP-1193 Provider.

© 2025 NEXUS Co., Ltd. All Rights Reserved.