> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# Using With Wagmi Connector

> Use the TypeScript OMS Wallet SDK as a wagmi connector.

The `@0xsequence/oms-wallet-wagmi-connector` package adapts an active TypeScript OMS Wallet SDK client to wagmi's connector API. Use it when your React app already uses wagmi hooks for account state, signing, chain switching, or transaction submission.

The connector does not render authentication UI. Authenticate with `@0xsequence/typescript-sdk` first, then connect through wagmi after the OMS Wallet session has an active wallet address.

## Install

Install the TypeScript SDK, the wagmi connector package, wagmi, `@wagmi/core`, viem, and TanStack Query for wagmi React hooks.

```bash theme={null}
pnpm add @0xsequence/typescript-sdk @0xsequence/oms-wallet-wagmi-connector wagmi @wagmi/core viem @tanstack/react-query
```

For npm or yarn projects:

```bash theme={null}
npm install @0xsequence/typescript-sdk @0xsequence/oms-wallet-wagmi-connector wagmi @wagmi/core viem @tanstack/react-query
yarn add @0xsequence/typescript-sdk @0xsequence/oms-wallet-wagmi-connector wagmi @wagmi/core viem @tanstack/react-query
```

## Create The Wagmi Config

Create one `OMSClient`, pass it to `omsWalletConnector`, and configure wagmi chains with viem transports. Wagmi chain definitions are separate from OMS Wallet `Network` entries, so pass both the wagmi `chains` and the OMS `networks`.

```typescript theme={null}
import {
  FeeOptionSelector,
  OMSClient,
  supportedNetworks,
} from '@0xsequence/typescript-sdk'
import { omsWalletConnector } from '@0xsequence/oms-wallet-wagmi-connector'
import { createConfig, http } from 'wagmi'
import { polygon, polygonAmoy } from 'wagmi/chains'

export const oms = new OMSClient({
  publishableKey: 'YOUR_PUBLISHABLE_KEY',
})

export const wagmiConfig = createConfig({
  chains: [polygonAmoy, polygon],
  connectors: [
    omsWalletConnector({
      client: oms,
      networks: supportedNetworks,
      initialChainId: polygonAmoy.id,
      transactionOptions: {
        selectFeeOption: FeeOptionSelector.firstAvailable,
      },
    }),
  ],
  transports: {
    [polygonAmoy.id]: http(),
    [polygon.id]: http(),
  },
})

declare module 'wagmi' {
  interface Register {
    config: typeof wagmiConfig
  }
}
```

**Parameters**

| Parameter            | Type                                      | Description                                                                                                   |
| -------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `client`             | `OmsWalletClientLike` or function         | `OMSClient` instance, or a function that resolves one.                                                        |
| `networks`           | `Network[]` or undefined                  | OMS Wallet networks used to validate connector chains. Defaults to `client.supportedNetworks` when available. |
| `initialChainId`     | `number` or undefined                     | Initial wagmi chain ID. Must exist in wagmi `chains` and the OMS networks list.                               |
| `transactionOptions` | `OmsWalletTransactionOptions` or function | Static transaction options, or a resolver called for each wagmi transaction request.                          |
| `id`                 | `string` or undefined                     | Optional connector ID. Defaults to `omsWallet`.                                                               |
| `name`               | `string` or undefined                     | Optional connector display name. Defaults to `OMS Wallet`.                                                    |
| `icon`               | `string` or undefined                     | Optional connector icon URL or data URI.                                                                      |

**Returns**

Returns a wagmi connector from `omsWalletConnector`.

## Wrap The React App

Pass the same `wagmiConfig` to `WagmiProvider`. Wagmi React hooks also require a TanStack Query client.

```tsx theme={null}
import React from 'react'
import { createRoot } from 'react-dom/client'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { WagmiProvider } from 'wagmi'
import { wagmiConfig } from './wagmiConfig'
import { App } from './App'

const queryClient = new QueryClient()

createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <WagmiProvider config={wagmiConfig}>
      <QueryClientProvider client={queryClient}>
        <App />
      </QueryClientProvider>
    </WagmiProvider>
  </React.StrictMode>,
)
```

## Connect After OMS Auth

Authenticate with the OMS Wallet SDK before calling wagmi `connect`. The connector checks `oms.wallet.walletAddress` and rejects the connection if there is no active wallet session.

```typescript theme={null}
import { connect } from '@wagmi/core'
import { polygonAmoy } from 'wagmi/chains'
import { wagmiConfig, oms } from './wagmiConfig'

await oms.wallet.startEmailAuth({ email: 'user@example.com' })
await oms.wallet.completeEmailAuth({ code: '123456' })

if (!oms.wallet.walletAddress) {
  throw new Error('OMS auth completed without an active wallet.')
}

const omsConnector = wagmiConfig.connectors.find(
  (connector) => connector.type === 'omsWallet',
)

if (!omsConnector) {
  throw new Error('OMS Wallet connector is not configured.')
}

await connect(wagmiConfig, {
  connector: omsConnector,
  chainId: polygonAmoy.id,
})
```

For redirect-based OIDC flows, complete the SDK redirect callback first, then connect through wagmi after the wallet session is active.

## Disconnect And Sign Out

Wagmi `disconnect` only disconnects wagmi state. It does not sign out the OMS Wallet SDK session.

```typescript theme={null}
import { disconnect } from '@wagmi/core'
import { wagmiConfig, oms } from './wagmiConfig'

await disconnect(wagmiConfig)
await oms.wallet.signOut()
```

After a wagmi-only disconnect, the connector marks itself manually disconnected and will not automatically reconnect on page refresh until the app calls wagmi `connect` again.

## Configure Fee Options

Wagmi transaction parameters do not include OMS fee-option preferences. Use `transactionOptions` on the connector to apply fee selection to wagmi transactions.

On testnets, all transactions are sponsored and do not require picking a fee option.

```typescript theme={null}
import {
  FeeOptionSelector,
  supportedNetworks,
} from '@0xsequence/typescript-sdk'
import { omsWalletConnector } from '@0xsequence/oms-wallet-wagmi-connector'
import { oms } from './wagmiConfig'

omsWalletConnector({
  client: oms,
  networks: supportedNetworks,
  transactionOptions: {
    selectFeeOption: FeeOptionSelector.firstAvailable,
  },
})
```

Use a resolver when the options should depend on the wagmi transaction request.

```typescript theme={null}
omsWalletConnector({
  client: oms,
  networks: supportedNetworks,
  transactionOptions: ({ chainId, request }) => ({
    selectFeeOption: async (feeOptions) => {
      const usdc = feeOptions.find(
        (option) => option.feeOption.token.symbol === 'USDC',
      )

      return usdc?.selection
    },
  }),
})
```

The connector calls `selectFeeOption` after preparing the transaction. The selector receives `FeeOptionWithBalance[]`, including each fee option and wallet balance data when available. Use `FeeOptionSelector.firstAvailable` to choose the first option the wallet can pay, or return `option.selection` from a custom selector.

## Send Transactions With Wagmi

Use wagmi transaction APIs after connecting. The connector always waits for an EVM transaction hash because wagmi `sendTransaction` must return a hash.

```typescript theme={null}
import { sendTransaction } from '@wagmi/core'
import { parseEther, type Address } from 'viem'
import { polygonAmoy } from 'wagmi/chains'
import { wagmiConfig } from './wagmiConfig'

const hash = await sendTransaction(wagmiConfig, {
  chainId: polygonAmoy.id,
  to: '0x1111111111111111111111111111111111111111' as Address,
  value: parseEther('0.01'),
})
```

Supported transaction fields are `from`, `to`, `value`, `data`, and `chainId`. The `to` field is required, so contract deployment is not supported through this connector.

The connector ignores wallet-managed execution fields that OMS Wallet does not accept through this path: `gas`, `gasPrice`, `maxFeePerGas`, `maxPriorityFeePerGas`, `nonce`, `type`, and `accessList`. Unknown transaction fields are rejected.

`waitForStatus: false` is not supported through the connector. Use `oms.wallet.sendTransaction` directly when you need the OMS transaction ID before an EVM transaction hash is available.

## Provider Scope

Use the connector through wagmi APIs. Do not treat `getProvider()` as a general RPC provider.

Supported provider methods are limited to wallet operations that map to the SDK:

| Method                       | Use                                                                |
| ---------------------------- | ------------------------------------------------------------------ |
| `eth_chainId`                | Read the active connector chain ID.                                |
| `net_version`                | Read the active connector network version.                         |
| `eth_accounts`               | Read the active OMS Wallet account.                                |
| `eth_requestAccounts`        | Connect the active OMS Wallet session.                             |
| `wallet_switchEthereumChain` | Switch across configured wagmi chains that OMS Wallet supports.    |
| `personal_sign`              | Sign string messages.                                              |
| `eth_signTypedData_v4`       | Sign typed data.                                                   |
| `eth_sendTransaction`        | Send a transaction through OMS Wallet.                             |
| `wallet_sendTransaction`     | Send a transaction through OMS Wallet.                             |
| `wallet_getCapabilities`     | Returns no capabilities unless OMS Wallet adds capability support. |

Direct read/RPC methods such as `eth_call`, `eth_estimateGas`, `eth_getBalance`, `eth_getCode`, `eth_getTransactionCount`, `eth_getTransactionReceipt`, and `eth_blockNumber` are not supported by the OMS Wallet provider. Use wagmi public transports for reads, or call `oms.wallet` directly for SDK operations.

Raw byte message signing is not supported because OMS Wallet signs string messages. Use `personal_sign` for messages and `eth_signTypedData_v4` for typed data.
