@cowprotocol/permit-utils

中文文档
3.13.1发布于 2026/11/11ISCTypeScriptESM + CJS构建来源已验证近 30 天下载 1978

收集用于处理象征性许可的提款机.

中文使用文档
文档目录6 节
  1. 安装
  2. 使用量
  3. getTokenPermitInfo
  4. getPermitUtilsInstance
  5. generatePermitHook
  6. checkIsCallDataAValidPermit

@cowprotocol/许可证使用

收集用于处理象征性许可的提款机.

安装

npm install @cowprotocol/permit-utils

使用量

getTokenPermitInfo

import { getTokenPermitInfo } from "@cowprotocol/permit-utils"

const permitInfo = await getTokenPermitInfo({
  spender, tokenAddress, tokenName, chainId, provider
})

getPermitUtilsInstance

import { getPermitUtilsInstance } from "@cowprotocol/permit-utils"

// Using a static account defined in the library
const staticEip2612PermitUtils = await getPermitUtilsInstance(chainId, provider)

// Using a provided account address
const accountEip2612PermitUtils = await getPermitUtilsInstance(chainId, provider, account)

generatePermitHook

import { generatePermitHook } from "@cowprotocol/permit-utils"

const hookData = await generatePermitHook({
  chainId,
  inputToken,
  spender,
  provider,
  permitInfo,
  eip2612Utils,
  account,
  nonce
})

checkIsCallDataAValidPermit

import { checkIsCallDataAValidPermit } from "@cowprotocol/permit-utils"

const isCallDataAValidPermit = await checkIsCallDataAValidPermit(
  account,
  chainId,
  eip2612Utils,
  tokenAddress,
  tokenName,
  callData,
  permitInfo
)

全流程示例

说明一下,我们将展示使用这种液态的电动装置,用许可钩下订单的流程.

  1. 检查给定的令牌是否是许可表
  2. 如果是的话, 生成一个许可钩
  3. 添加许可钩子以订购 appData
  4. 定期检查许可证是否仍然有效
import { checkIsCallDataAValidPermit, generatePermitHook, getPermitUtilsInstance, getTokenPermitInfo } from '@cowprotocol/permit-utils'
import { stringifyDeterministic, OrderBookApi } from '@cowprotocol/cow-sdk'


// Check whether token is permittable.
// No account info is necessary.
// `spender` could in theory be any address
// `tokenName` must always match the contract
const permitInfo = await getTokenPermitInfo({
  spender, tokenAddress, tokenName, chainId, provider
})

// Not able to tell or not permittable
if (!permitInfo) {
  return
}

// Pass in an account address as we'll need the user to sign the actual permit
const eip2612Utils = await getPermitUtilsInstance(chainId, provider, account)

// Need to know what the current permit nonce is
const nonce = await eip2612Utils.getTokenNonce(inputToken.address, account)

// Calling this fn should trigger the signature in the user's wallet
const hookData = await generatePermitHook({
  chainId,
  inputToken,
  spender, // Now `spender` must be the real one
  provider,
  permitInfo,
  eip2612Utils,
  account, // `account` should also be the user's
  nonce
})

// Add the hookData to the order's appData
// See the full reference on https://www.npmjs.com/package/@cowprotocol/sdk-app-data?activeTab=code
const appData = { version: '0.10.0', metadata: { hooks: { pre: [hookData] } } }

// The order expects the stringified JSON doc
const fullAppData = await stringifyDeterministic(appData)

// Build cow-sdk orderBookApi instance
const orderBookApi = new OrderBookApi()

// Note: price quoting is a required step before placing the order but has been left out of this example for brevity

// Place order
const orderId = await orderBookApi.sendOrder(
  {
    ...orderParameters,
    quoteId, // Must be fetched before hand, and also include the appData in the params
    appData: fullAppData // <-- The order will be placed with the permit info
  },
  { chainId }
)

// Now we check whether the permit included in the order is still valid
// It'll become invalid when another permit is executed
// This check does not consider whether the `address` has enough allowance, it purelly checks the permit validity.

// CallData is part of the hookData
const callData = hookData.callData

// All properties must match what was used when the hookData was generated
const isCallDataAValidPermit = await checkIsCallDataAValidPermit(
  account,
  chainId,
  eip2612Utils,
  tokenAddress,
  tokenName,
  callData,
  permitInfo
)

版本与发布记录

@cowprotocol/permit-utils 共发布 53 个版本,首次发布于 2023/10/31;过去 12 个月发布了 38 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.13.1latest2026/11/113 天前
3.13.02026/11/104 天前
3.12.12026/11/059 天前
3.12.02026/10/2817 天前
3.11.12026/10/2718 天前
3.11.02026/10/2124 天前

其他发布通道:next → 2.1.0。

关于 @cowprotocol/permit-utils 的常见问题

@cowprotocol/permit-utils 是什么?

收集用于处理象征性许可的提款机.

如何安装 @cowprotocol/permit-utils?

在项目目录运行 npm install @cowprotocol/permit-utils,或使用 pnpm add / yarn add / bun add。

@cowprotocol/permit-utils 支持 TypeScript 吗?

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

@cowprotocol/permit-utils 支持 ESM 还是 CommonJS?

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

@cowprotocol/permit-utils 可以商用吗?

@cowprotocol/permit-utils 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cowprotocol/permit-utils 的下载量有多少?

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

@cowprotocol/permit-utils 还在维护吗?

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