@0xtrails/adapter-wagmi

中文文档
0.20.0发布于 2026/10/22Apache-2.0TypeScriptES Module近 30 天下载 3965

Use Trails with wagmi

原始使用文档
文档目录8 节
  1. Install
  2. Quick start: widget with your wagmi provider
  3. App-level setup with TrailsProvider
  4. Runtime ownership
  5. Optional: custom wallet labels
  6. Branding an embedded wallet as your own
  7. Tips
  8. License

@0xtrails/adapter-wagmi

Use Trails with wagmi.

This adapter lets Trails use the wagmi setup your app already has. Use it when your app owns WagmiProvider, chains, transports, and connectors, and you want the Trails widget or hooks to share that wallet state. The primary integration target is wagmi 3, with wagmi 2 kept as a compatibility target.

The adapter auto-detects a surrounding WagmiProvider by default:

  • surrounding WagmiProvider and no wagmiConfig option → bridge into the host-owned wagmi runtime
  • same wagmiConfig instance as the surrounding WagmiProvider → bridge into the host-owned wagmi runtime
  • no matching surrounding WagmiProvider and a wagmiConfig option → mount an adapter-owned wagmi runtime with the provided config

For a truly separate Trails-owned runtime, create and pass a separate wagmi config instance.

Install

npm install 0xtrails @0xtrails/adapter-wagmi wagmi viem @tanstack/react-query

Supported wagmi versions:

  • Primary: wagmi@^3.2.0
  • Compatibility: wagmi@^2.19.0

The package peer range remains wagmi@^2.19.0 || ^3.2.0 so existing wagmi 2 hosts can keep using the same adapter.

Quick start: widget with your wagmi provider

import { TrailsWidget } from '0xtrails'
import { wagmiAdapter } from '@0xtrails/adapter-wagmi'
import { WagmiProvider } from 'wagmi'

const apiKey = 'YOUR_TRAILS_API_KEY'

// Automatically uses the surrounding WagmiProvider.
const adapters = [wagmiAdapter()]

export function App() {
  return (
    <WagmiProvider config={wagmiConfig}>
      <TrailsWidget apiKey={apiKey} adapters={adapters} renderInline />
    </WagmiProvider>
  )
}

You only need to pass wagmiConfig when Trails should be able to mount an adapter-owned wagmi runtime fallback.

App-level setup with TrailsProvider

Use this when Trails hooks and the widget should share the same adapter.

import { TrailsProvider, TrailsWidget } from '0xtrails'
import { wagmiAdapter } from '@0xtrails/adapter-wagmi'
import { WagmiProvider } from 'wagmi'

const apiKey = 'YOUR_TRAILS_API_KEY'
const adapters = [wagmiAdapter()]

export function App() {
  return (
    <WagmiProvider config={wagmiConfig}>
      <TrailsProvider config={{ trailsApiKey: apiKey, adapters }}>
        <TrailsWidget renderInline />
      </TrailsProvider>
    </WagmiProvider>
  )
}

Runtime ownership

managedBy is only needed when you pass multiple adapters as wrapped entries. It controls wallet lifecycle ownership in Trails, not whether the wagmi adapter bridges to a parent provider.

const hostAdapter = wagmiAdapter({ wagmiConfig: hostWagmiConfig })
const trailsAdapter = wagmiAdapter({ wagmiConfig: trailsWagmiConfig })

const adapters = [
  { adapter: hostAdapter, managedBy: 'host' },
  { adapter: trailsAdapter, managedBy: 'trails' },
]

Use managedBy: 'host' when Trails can use the wallet but should not own its lifecycle, for example hiding disconnect actions for a host-controlled wallet. Use managedBy: 'trails' for wallet options that Trails should own.

Optional: custom wallet labels

Pass wallets if you want to control how a host wallet appears in Trails. name and icon replace the catalog's label and logo everywhere Trails shows the wallet: the connect list, the connected chip, the funding selector and the recipient rows.

const adapters = [
  wagmiAdapter({
    wagmiConfig,
    wallets: [
      {
        id: 'host-wallet',
        name: 'My Wallet',
        icon: 'https://my.app/wallet.png',
        flow: 'direct',
        placement: 'featured',
      },
    ],
  }),
]

Branding an embedded wallet as your own

Embedded wallets (Privy, Sequence) are host-login identities, so Trails never lists them on its own; a host opts one in with a featured descriptor. The same descriptor is where you rename it. Users of an app built on Privy should see the app's wallet, not Privy's:

wagmiAdapter({
  wagmiConfig: privyWagmiConfig,
  wallets: [
    {
      id: 'privy',
      name: 'XYZ Wallet',
      icon: 'https://xyz.app/wallet.png',
      flow: 'embedded',
      placement: 'featured',
      connect: connectPrivyEmbedded,
    },
  ],
})

Trails resolves any @privy-io/wagmi connector to the id privy, so the descriptor matches the connection whether the user connected through Trails or was already signed in. Privy's own login modal and its "Protected by Privy" footer are configured in the Privy dashboard, outside Trails.

Tips

  • Put adapters on TrailsProvider config.adapters for app-level setup.
  • Put adapters on TrailsWidget adapters for widget-only setup.
  • Do not pass adapters in both places at the same time.
  • Use wagmiAdapter() when Trails should auto-detect and share your existing wagmi runtime.
  • Pass the same wagmiConfig instance when Trails should share that runtime but still have an adapter-owned fallback.
  • Use a separate wagmiConfig instance when Trails should mount a separate adapter-owned runtime.
  • managedBy controls lifecycle ownership in composite adapter lists; it does not override wagmi runtime matching.

License

Apache-2.0

版本与发布记录

@0xtrails/adapter-wagmi 共发布 17 个版本,首次发布于 2026/05/08;过去 12 个月发布了 17 个版本。

版本发布日期距今
0.20.0latest2026/10/2216 天前
0.19.12026/10/081 个月前
0.18.72026/10/081 个月前
0.18.62026/09/171 个月前
0.18.52026/09/111 个月前
0.18.42026/09/012 个月前

其他发布通道:canary → 0.0.0-canary-f34333b4e54352fe3e761ba2f3ffd4117d041fe6。

关于 @0xtrails/adapter-wagmi 的常见问题

@0xtrails/adapter-wagmi 是什么?

Use Trails with wagmi

如何安装 @0xtrails/adapter-wagmi?

在项目目录运行 npm install @0xtrails/adapter-wagmi,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:viem(^2.45.0)、react(^18.0.0 || ^19.0.0)、wagmi(^2.19.0 || ^3.2.0)、@tanstack/react-query(^5.90.20)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@0xtrails/adapter-wagmi 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@0xtrails/adapter-wagmi 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@0xtrails/adapter-wagmi 可以商用吗?

@0xtrails/adapter-wagmi 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@0xtrails/adapter-wagmi 的下载量有多少?

根据 npm 官方下载统计,@0xtrails/adapter-wagmi 在 2026/10/04 – 2026/11/02 这 30 天内被下载 3,965 次,日均约 132 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@0xtrails/adapter-wagmi 还在维护吗?

最新版本 0.20.0 发布于 2026/10/22(16 天前);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2026/05/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。