@anywalletkit/wallet-evm

中文文档
0.7.0发布于 2026/11/03Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 2765

EVM wallet for Any Wallet Kit: BIP-32 m/44'/60'/0'/0/i accounts, EIP-191 / EIP-712 / EIP-1559 signing, ERC-20 transfer and approve, built on viem.

原始使用文档
文档目录3 节
  1. Install
  2. Token info
  3. Safety layer

@anywalletkit/wallet-evm

npm

EVM accounts for Any Wallet Kit, derived at m/44'/60'/0'/0/i — the same path as MetaMask and ethers, pinned by golden vectors in @anywalletkit/conformance.

Install

npm install @anywalletkit/wallet-evm
# or: pnpm add @anywalletkit/wallet-evm  ·  yarn add @anywalletkit/wallet-evm

On npm: @anywalletkit/wallet-evm, published from the release workflow with provenance.

import WalletManagerEvm from '@anywalletkit/wallet-evm'

const wallet = new WalletManagerEvm(seedPhrase, { provider: ['https://rpc-a', 'https://rpc-b'] })
const account = await wallet.getAccount(0)
await account.transfer({ recipient: '0x…', amount: 10n ** 15n })                  // ETH
await account.transfer({ token: USDT, recipient: '0x…', amount: 1_000_000n })      // ERC-20
await account.approve({ token: USDT, spender: ROUTER, amount: 1_000_000n })
const sig = await account.signTypedData({ domain, types, message })               // EIP-712
wallet.dispose()                                                                  // zeroizes seed + keys

Offline signing: omit provider, pass chainId (or put it on the tx) and call signTransaction with every field set — nothing touches the network.

Token info

getTokenInfo(address) reads an ERC-20 from its contract: { address, standard: 'erc20', decimals, symbol, name, totalSupply, flags }. bytes32 symbols (MKR) are decoded; text that is not UTF-8 is ''. flags holds upgradeable when the address is an EIP-1967 / EIP-1822 / beacon / ZeppelinOS proxy. No code, an EIP-7702-delegated account or no decimals() (an NFT, a plain contract) throws NotATokenError; RPC failures are thrown as they are. @anywalletkit/tokens builds the "add a token" flow on it.

Safety layer

Every send goes through, in order: static refusals → simulation → fee cap → sign → broadcast.

  • What you sign. describeTransaction(tx, {chainId}) and describeTypedData(typed, {chainId, account}) are pure, offline decoders for a confirmation screen: kind (native-transfer, erc20-transfer, erc20-approve, contract-call, eip7702-delegation, …; permit, permit2, safe-tx, generic), decoded fields, and warnings (approve-unlimited, to-zero-address, chain-mismatch, deadline-passed, owner-mismatch, legacy-fee-fields).
  • Hard refusals before any signature: a tx or typed-data domain for another chain throws ChainMismatchError (override typed data with allowCrossChainTypedData); value to the zero address throws UnsafeTransactionError (override with allowBurn).
  • Simulation. simulateTransaction(tx) runs eth_call + gas estimate and returns {ok, gas, returnData} or {ok: false, reason, data} with the decoded Error(string) / Panic / custom-error selector. sendTransaction / transfer / approve simulate first and throw SimulationError instead of broadcasting a revert; simulate: false opts out. The estimated gas is reused, so the network is asked once.
  • Fee cap. transferMaxFee / transactionMaxFee are checked on the transaction about to be signed — gas limit × its gasPrice / maxFeePerGas, fee fields you set yourself included — before every signature. quoteSendTransaction prices the same fields, so a kit maxFee policy sees them too.
  • Fee-rate ceiling. A gasPrice / maxFeePerGas / maxPriorityFeePerGas you set yourself is refused (UnsafeTransactionError) when its rate is above maxFeeRateMultiplier (default 10) × the network's current quote (the higher of eth_gasPrice and the EIP-1559 estimate) and above 10 gwei. Fees the account fills in are not checked; without a provider, or when the quote cannot be read, nothing is refused (use transactionMaxFee for offline signing); the quote is waited for at most 5 s. maxFeeRateMultiplier: null (or Infinity) turns it off; a value below 1 throws a RangeError when the account is created.
  • Broadcast. A lost answer throws BroadcastUnknownError with the locally computed hash: watch it, do not send again. With several RPCs, already known from the next one is the same transaction and resolves to its hash. nonce too low is re-signed with the next nonce only when the nonce is proven taken by another transaction: at least two distinct configured RPCs count the account's mined transactions past it (latest) and none of them knows the rejected hash. Otherwise — one RPC configured, or the RPCs disagree — the send throws NonceConflictError (a BroadcastUnknownError: maybeSent, hash, plus nonce and the node's nextNonce) and nothing new is signed, since the RPC that refused may still hold and broadcast the signed bytes. Show "the network didn't confirm — check activity, then retry"; the account's next send skips the refused nonce. replacement transaction underpriced is never retried.
  • EIP-2612 permit. getPermitInfo(token) reads name/version/nonces/DOMAIN_SEPARATOR and reports supported only when the rebuilt EIP-712 domain equals the contract's own; signPermit({token, spender, value, deadline}) returns {signature, v, r, s, nonce, deadline, typedData}. DAI's legacy permit(holder, spender, nonce, expiry, allowed) is not supported.
const d = describeTransaction(tx, { chainId: await account.getChainId() })
if (d.warnings.some((w) => w.code === 'approve-unlimited')) ask(d)
const sim = await account.simulateTransaction(tx)
if (!sim.ok) show(sim.reason)

版本与发布记录

@anywalletkit/wallet-evm 共发布 14 个版本,首次发布于 2026/10/25;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/11/035 天前
0.6.02026/10/308 天前
0.5.02026/10/309 天前
0.4.12026/10/2910 天前
0.4.02026/10/2810 天前
0.3.12026/10/2811 天前

关于 @anywalletkit/wallet-evm 的常见问题

@anywalletkit/wallet-evm 是什么?

EVM wallet for Any Wallet Kit: BIP-32 m/44'/60'/0'/0/i accounts, EIP-191 / EIP-712 / EIP-1559 signing, ERC-20 transfer and approve, built on viem.

如何安装 @anywalletkit/wallet-evm?

在项目目录运行 npm install @anywalletkit/wallet-evm,或使用 pnpm add / yarn add / bun add。

@anywalletkit/wallet-evm 支持 TypeScript 吗?

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

@anywalletkit/wallet-evm 支持 ESM 还是 CommonJS?

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

@anywalletkit/wallet-evm 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anywalletkit/wallet-evm 可以商用吗?

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

@anywalletkit/wallet-evm 的下载量有多少?

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

@anywalletkit/wallet-evm 还在维护吗?

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