@bosonprotocol/x402-evm

中文文档
0.2.2发布于 2026/09/14Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 5161

Boson Protocol EVM calldata + adapter glue for the x402 escrow scheme — inner-action ABI encoding for the commit step and viem ↔ Web3LibAdapter bridges. Wraps @bosonprotocol/core-sdk for everything else.

原始使用文档
文档目录5 节
  1. Scope
  2. What this package deliberately does NOT ship
  3. Meta-tx signing (default) — coreSdk.signMetaTxXxx
  4. Direct on-chain submission — coreSdk.xxx
  5. Token-side approve / Permit2 approval

@bosonprotocol/x402-evm

EVM-specific calldata builders for the Boson Protocol escrow scheme — the EVM half of the x402B implementation.

See docs/boson-impl-00-overview.md in the monorepo root for context.

Scope

This package ships only what the x402B escrow scheme needs beyond what @bosonprotocol/core-sdk already provides:

SubpathPurpose
./actionsInner-action ABI encoding for the commit step. buildCreateOfferAndCommitCalldata (Flow A, deferred-redeem) and buildCreateOfferCommitAndRedeemCalldata (Flow B, atomic commit+redeem) each return the { functionName, functionSignature } pair that feeds the meta-tx typed-data the buyer signs. Both delegate to metaTx.handler.signMetaTx*({ returnTypedDataToSign: true }) in core-sdk so the selector literal and ABI encoding come from the same source the buyer signs against — no drift between signing and verification.
./adaptersviem ↔ Web3LibAdapter bridges. walletClientToWeb3LibAdapter wraps a viem WalletClient + PublicClient so coreSdk.executeMetaTransaction(...) (the unified entrypoint for the outer envelope) can submit through viem-configured transports. Submission failures surface as a tagged RelayerSubmitError so callers can preserve precise error codes (INSUFFICIENT_FUNDS_FOR_GAS, ONCHAIN_REVERT, INTERNAL_ERROR).

The outer meta-tx envelope (executeMetaTransaction / executeMetaTransactionWithTokenTransferAuthorization) is not re-implemented here. Submit through core-sdk's coreSdk.executeMetaTransaction(metaTxParams), which accepts an optional transferAuthorizations array and routes to the right on-chain entrypoint internally.

What this package deliberately does NOT ship

Boson's meta-tx and direct-call flows for every other action are already fully covered by @bosonprotocol/core-sdk. Reach for it directly:

Meta-tx signing (default) — coreSdk.signMetaTxXxx

Each signMetaTxXxx method on a configured CoreSDK instance uses the bespoke EIP-712 type the protocol's MetaTransactionsHandlerFacet expects for that action family (MetaTxExchange for redeem/complete/cancel/revoke/raise/retract/escalate, MetaTxDisputeResolution for resolveDispute, generic MetaTransaction for createOfferAndCommit and friends). It returns SignedMetaTx = { functionName, functionSignature, r, s, v } — exactly the buyer-side payload the X-PAYMENT header carries, ready for the facilitator to submit via coreSdk.executeMetaTransaction(metaTxParams).

const signed = await coreSdk.signMetaTxRedeemVoucher({ nonce, exchangeId });
// signed = { functionName: "redeemVoucher(uint256)", functionSignature, r, s, v }

coreSdk fills web3Lib, metaTxHandlerAddress, and chainId from the SDK instance, so the call site stays minimal. The standalone metaTx.handler.signMetaTxXxx exports are also available if you need them without a CoreSDK instance.

Direct on-chain submission — coreSdk.xxx

For the on-chain channel (buyer paying their own gas, or the "onchain" fallback in nextActions[i].channels), use the same CoreSDK mixin methods that handle signing and submission in one call:

const tx = await coreSdk.redeemVoucher(exchangeId);
// → also: completeExchange, cancelVoucher, revokeVoucher,
//          raiseDispute, retractDispute, escalateDispute, resolveDispute
await tx.wait();

Pass returnTxInfo: true to get back a TransactionRequest for manual submission (e.g. when handing it to a relayer or batcher) instead of broadcasting through the SDK's web3Lib.

Token-side approve / Permit2 approval

Calldata builders for the buyer's pre-approval transaction (used by tokenAuthStrategy: "none") and the one-time Permit2 contract approval live in @bosonprotocol/x402-core:

import {
  createErc20ApprovalTx,
  createPermit2ApprovalTx,
} from "@bosonprotocol/x402-core/eip712/token-auth";

版本与发布记录

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

版本发布日期距今
0.2.2latest2026/09/141 个月前
0.2.2-alpha-0alpha2026/09/141 个月前
0.2.12026/06/114 个月前
0.2.1-alpha-02026/06/114 个月前
0.2.02026/05/285 个月前
0.1.1-alpha-22026/05/285 个月前

关于 @bosonprotocol/x402-evm 的常见问题

@bosonprotocol/x402-evm 是什么?

Boson Protocol EVM calldata + adapter glue for the x402 escrow scheme — inner-action ABI encoding for the commit step and viem ↔ Web3LibAdapter bridges. Wraps @bosonprotocol/core-sdk for everything else.

如何安装 @bosonprotocol/x402-evm?

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

@bosonprotocol/x402-evm 支持 TypeScript 吗?

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

@bosonprotocol/x402-evm 支持 ESM 还是 CommonJS?

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

@bosonprotocol/x402-evm 可以商用吗?

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

@bosonprotocol/x402-evm 的下载量有多少?

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

@bosonprotocol/x402-evm 还在维护吗?

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