@dynamic-labs-sdk/wagmi

中文文档
1.51.0发布于 2026/11/11TypeScriptESM + CJS近 30 天下载 4668

Official wagmi support for the Dynamic JS SDK. Expose a Dynamic-managed EVM wallet account (embedded/OTP or external) as a wagmi connector so useAccount, useSendTransaction, useReadContract, and the rest of the wagmi/viem hook ec

原始使用文档
文档目录8 节
  1. Installation
  2. Which API to use
  3. Vanilla JS
  4. Switching the target wallet account
  5. Pinning wagmi to one specific account
  6. React
  7. What's supported
  8. Notes & limitations

@dynamic-labs-sdk/wagmi

Official wagmi support for the Dynamic JS SDK. Expose a Dynamic-managed EVM wallet account (embedded/OTP or external) as a wagmi connector so useAccount, useSendTransaction, useReadContract, and the rest of the wagmi/viem hook ecosystem work against Dynamic wallets — with Dynamic remaining the source of truth for wallet state.

Installation

npm install @dynamic-labs-sdk/wagmi wagmi @wagmi/core viem @tanstack/react-query

wagmi, @wagmi/core and viem are peer dependencies. wagmi and @tanstack/react-query are only required for the React helpers.

Which API to use

Use the automatic sync — syncDynamicWagmi in vanilla JS, SyncDynamicWagmi / useSyncDynamicWagmi in React. Both keep wagmi pointed at Dynamic's selected EVM wallet account, so setSelectedWalletAccount(...) is all you ever call to move wagmi.

Vanilla JSReact
Keep wagmi on Dynamic's selected accountsyncDynamicWagmiSyncDynamicWagmi (or the useSyncDynamicWagmi hook)
Bridge one specific account yourselfcreateDynamicWagmiConnectorcreateDynamicWagmiConnector

createDynamicWagmiConnector is the primitive both sync helpers are built on. It bridges exactly one account — the one you pass in — and never follows Dynamic's selection, so reach for it only when you deliberately want to pin wagmi to a specific account.

Vanilla JS

syncDynamicWagmi keeps a wagmi config on Dynamic's selected EVM wallet account, with no React involved. It subscribes to Dynamic's wallet events and drives wagmi's connect / disconnect whenever that selection changes — login, wallet switch, or logout — and returns a function that stops the sync.

Create your wagmi config once at startup — you don't have a wallet account yet, and you never rebuild the config. There is no Dynamic connector in createConfig:

import { createConfig, http } from '@wagmi/core';
import { mainnet } from 'viem/chains';

export const config = createConfig({
  chains: [mainnet],
  transports: { [mainnet.id]: http() },
});

Then start the sync once — there is no walletAccount argument, and you never build a connector yourself:

import { setSelectedWalletAccount } from '@dynamic-labs-sdk/client';
import { syncDynamicWagmi } from '@dynamic-labs-sdk/wagmi';

const stopSync = syncDynamicWagmi({ config });

// When you're done (teardown / logout):
stopSync();

It can start before the user has a wallet: wagmi stays disconnected until an EVM wallet account is selected.

If you use multiple Dynamic clients, pass the client as the second argument:

const stopSync = syncDynamicWagmi({ config }, client);

Switching the target wallet account

Switching is a Dynamic call — no wagmi code:

import { setSelectedWalletAccount } from '@dynamic-labs-sdk/client';

// wagmi re-points to nextWalletAccount automatically.
await setSelectedWalletAccount({ walletAccount: nextWalletAccount });

Pinning wagmi to one specific account

If you want wagmi on an account of your choosing rather than Dynamic's selected one, build the connector yourself. The wallet provider is derived from the account, so you only ever pass the account:

import { connect, disconnect, getConnections } from '@wagmi/core';
import { createDynamicWagmiConnector } from '@dynamic-labs-sdk/wagmi';

await connect(config, {
  connector: createDynamicWagmiConnector({ walletAccount }),
});

// Dynamic-backed connectors carry `type: 'dynamic'`, so you can disconnect
// yours by name and leave connections your app made elsewhere untouched.
const dynamicConnections = getConnections(config).filter(
  (connection) => connection.connector.type === 'dynamic'
);

for (const { connector } of dynamicConnections) {
  await disconnect(config, { connector });
}

This connector is bound to that single account and does not react to setSelectedWalletAccount(...); to point it elsewhere, disconnect it and connect a connector built for the other account.

If you use multiple Dynamic clients, pass the client as the second argument:

const connector = createDynamicWagmiConnector({ walletAccount }, client);

React

SyncDynamicWagmi (or the useSyncDynamicWagmi hook) is the React wrapper around syncDynamicWagmi — it runs the sync for the component's lifetime. It watches Dynamic's selected EVM wallet account and drives wagmi's connect / disconnect for you whenever that selection changes — login, wallet switch, or logout. You do not pass a walletAccount, and you never build a connector yourself.

The payoff: call Dynamic's setSelectedWalletAccount(...) anywhere in your app and wagmi follows automatically — useAccount and friends re-point to the newly selected account with no extra wiring. Dynamic stays the source of truth; wagmi is a read-only mirror. It renders nothing.

import { DynamicProvider } from '@dynamic-labs-sdk/react-hooks';
import { SyncDynamicWagmi } from '@dynamic-labs-sdk/wagmi/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { WagmiProvider, createConfig, http } from 'wagmi';
import { mainnet } from 'wagmi/chains';

// Your Dynamic client, created once via createDynamicClient(...).
import { client } from './dynamicClient';

// Dynamic handles wallet discovery, so disable wagmi's own injected discovery.
const config = createConfig({
  chains: [mainnet],
  multiInjectedProviderDiscovery: false,
  transports: { [mainnet.id]: http() },
});

const queryClient = new QueryClient();

// DynamicProvider makes the client available to the rest of Dynamic's React
// hooks (useUser, useGetWalletAccounts, ...). SyncDynamicWagmi uses the same
// client to keep wagmi in sync.
export const Providers = ({ children }) => (
  <DynamicProvider client={client}>
    <WagmiProvider config={config}>
      <QueryClientProvider client={queryClient}>
        <SyncDynamicWagmi config={config} />
        {children}
      </QueryClientProvider>
    </WagmiProvider>
  </DynamicProvider>
);

Once mounted, any wagmi hook mirrors the selected Dynamic wallet, and switching accounts is just a Dynamic call — no wagmi code:

import { setSelectedWalletAccount } from '@dynamic-labs-sdk/client';
import { useAccount } from 'wagmi';

const { address, isConnected } = useAccount();

// wagmi re-points to nextWalletAccount automatically.
await setSelectedWalletAccount({ walletAccount: nextWalletAccount });

The hook is also available directly:

import { useSyncDynamicWagmi } from '@dynamic-labs-sdk/wagmi/react';

useSyncDynamicWagmi({ config });

What's supported

  • connect / disconnect
  • getAccounts / getChainId / isAuthorized
  • switchChain
  • Forwarding Dynamic wallet events (account change, network change, disconnect) to wagmi.

Notes & limitations

  • v1 bridges a single EVM account at a time (the selected one when syncing, the one you pass otherwise). Bridging multiple EVM accounts simultaneously is a follow-up — let us know if you need this feature.
  • Only EVM wallet accounts are bridged. Selecting a non-EVM wallet account (e.g. Solana) leaves wagmi disconnected until an EVM wallet account is selected again.
  • Not every Dynamic wallet provider can change networks. When the underlying provider cannot, switchChain — and connect(config, { connector, chainId }) with a chain other than the wallet's current one — rejects with wagmi's SwitchChainNotSupportedError instead of silently staying on the old network.

版本与发布记录

@dynamic-labs-sdk/wagmi 共发布 42 个版本,首次发布于 2026/08/13;过去 12 个月发布了 42 个版本。

版本发布日期距今
1.51.0latest2026/11/112 天前
1.50.02026/11/058 天前
1.49.12026/11/0210 天前
1.49.02026/10/3113 天前
1.48.02026/10/3014 天前
1.47.02026/10/2816 天前

关于 @dynamic-labs-sdk/wagmi 的常见问题

@dynamic-labs-sdk/wagmi 是什么?

Official wagmi support for the Dynamic JS SDK. Expose a Dynamic-managed EVM wallet account (embedded/OTP or external) as a wagmi connector so useAccount, useSendTransaction, useReadContract, and the rest of the wagmi/viem hook ec

如何安装 @dynamic-labs-sdk/wagmi?

在项目目录运行 npm install @dynamic-labs-sdk/wagmi,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:viem(^2.28.4)、@wagmi/core(^2.0.0 || ^3.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dynamic-labs-sdk/wagmi 支持 TypeScript 吗?

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

@dynamic-labs-sdk/wagmi 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dynamic-labs-sdk/wagmi 可以商用吗?

@dynamic-labs-sdk/wagmi 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@dynamic-labs-sdk/wagmi 的下载量有多少?

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

@dynamic-labs-sdk/wagmi 还在维护吗?

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