@cowprotocol/sdk-app-data

中文文档
6.1.1发布于 2026/11/04MITTypeScriptESM + CJS构建来源已验证近 30 天下载 10.3万

CoW Protocol AppData schema definitions

原始使用文档
文档目录8 节
  1. Test coverage
  2. Installation
  3. Usage
  4. Using via Cow SDK
  5. Schemas
  6. Type definitions
  7. Constants
  8. Utils

Cow AppData SDK

Test coverage

StatementsBranchesFunctionsLines
StatementsBranchesFunctionsLines

AppData schema definitions

These schemas are used in the data encoded on appData field for CowProtocol orders.

For more details, check the docs.

Installation

pnpm add @cowprotocol/sdk-app-data

Usage

import { AppDataSdk } from '@cowprotocol/sdk-app-data'
import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
import { JsonRpcProvider, Wallet } from 'ethers'

// Proper adapter initialization
const provider = new JsonRpcProvider('YOUR_RPC_URL')
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
const adapter = new EthersV6Adapter({ provider, signer: wallet })

export const appDataSdk = new AppDataSdk(adapter)

const appCode = 'YOUR_APP_CODE'
const environment = 'prod'
const referrer = { address: `REFERRER_ADDRESS` }

const quote = { slippageBips: 1 } // Slippage percent, it's 0 to 100
const orderClass = { orderClass: 'market' } // "market" | "limit" | "liquidity"

const appDataDoc = await appDataSdk.generateAppDataDoc({
  appCode,
  environment,
  metadata: {
    referrer,
    quote,
    orderClass,
  },
})

// Get appData info
const { appDataContent, appDataHex, cid } = await appDataSdk.getAppDataInfo(appDataDoc)

// The app-data hex string (app-data part of the order struct)
console.log(appDataHex)

// Full appData content. It will be the exact string that if hashed using keccak-256 you would get the
// returned appDataHex (app-data hex part of the order struct).
console.log(appDataContent)

// IPFS's content identifier. Normally you don't need to use this.
// The app-data content can be uploaded to IPFS. If its uploaded, this CID will be the content identifier.
// This is a way to be able to connect the appDataHex (app-data hex part of the order struct) to its
// content using a decentralized system.
console.log(cid)

Using via Cow SDK

You can also import AppDataSdk directly from the main SDK:

import { AppDataSdk } from '@cowprotocol/cow-sdk'
import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
import { JsonRpcProvider, Wallet } from 'ethers'

// Proper adapter initialization
const provider = new JsonRpcProvider('YOUR_RPC_URL')
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
const adapter = new EthersV6Adapter({ provider, signer: wallet })

export const appDataSdk = new AppDataSdk(adapter)
// ... rest of the usage remains the same

Schemas

Schemas are exposed as json files, where the version is the file name:

// Getting the version v0.4.0
// If you use TypeScript, enable `resolveJsonModule` in tsconfig.
const schema = require('@cowprotocol/sdk-app-data/schemas/v0.4.0.json')

// Now you can for example run validation against a schema

Type definitions

There are also type definitions

import { v0_4_0 } from '@cowprotocol/sdk-app-data'

// Note: this example is
function createAppDataV0_4_0(appCode: v0_4_0.AppCode, metadata: v0_4_0.Metadata): v0_4_0.AppDataRootSchema {
  return {
    version: '0.4.0',
    appCode,
    metadata,
  }
}

Constants

The latest version names are exposed as constants

import {
  LATEST_APP_DATA_VERSION,
  LATEST_QUOTE_METADATA_VERSION,
  LATEST_REFERRER_METADATA_VERSION,
} from '@cowprotocol/sdk-app-data'

Utils

Get appData schema

To get a schema definition by version

import { getAppDataSchema } from '@cowprotocol/sdk-app-data'

const schema = getAppDataSchema('0.1.0')

It'll throw if the version does not exist

Validate appDataDoc

To validate a document, pass it to validateAppDataDoc. It'll return an object with a boolean indicating success and errors, if any. The version to validate against will be taken from the doc itself.

import { validateAppDataDoc } from '@cowprotocol/sdk-app-data'

let doc = { version: '0.4.0', metadata: {} }

let result = await validateAppDataDoc(doc)
console.log(result) // { success: true }

doc = { version: '0.0.0', metadata: {} }

result = await validateAppDataDoc(doc)
// Contrary to `getAppDataSchema`, invalid or non-existing schemas won't throw
console.log(result) // { success: false, errors: 'AppData version 0.0.0 doesn\'t exist'}

Contribute

Fork the repo so you can create a new PR. Then:

  1. Add a new version for the schema using the semver convention
  • Just duplicate the latest version i.e. src/schemas/<old-version>.json to src/schemas/<new-version>.json
  1. If you are adding a new meta-data
  1. If you are modifying an existing meta-data
  • Version it using the semver convention
  • You will need to create the new file for the meta-data schema: <meta-data-name>/<new-version>.json
  • Update it in the main schema you just created in step 1: Set it to "<meta-data-name>": { "$ref": "<meta-data-name>/<new-version>.json#" }
  1. Generate the typescript types
  • Run pnpm build. It auto-detects every src/schemas/v*.json file and regenerates the types, and the latest version is derived automatically (highest semver), so there is no constant to update by hand.
  1. Make a test focusing on the new or modified meta-data:
  1. Create the PR and document it together with the motivation for the changes

Note: The examples above point to the legacy app-data repository before the adapter system was introduced. For new implementations, please use the current repository with proper adapter initialization as shown in the usage examples above.

版本与发布记录

@cowprotocol/sdk-app-data 共发布 74 个版本,首次发布于 2025/08/02;过去 12 个月发布了 54 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.1.1latest2026/11/046 天前
6.1.02026/11/046 天前
6.0.132026/11/037 天前
6.0.122026/10/2615 天前
6.0.112026/10/1328 天前
6.0.102026/10/091 个月前

其他发布通道:next → 4.1.0-beta.0。

关于 @cowprotocol/sdk-app-data 的常见问题

@cowprotocol/sdk-app-data 是什么?

CoW Protocol AppData schema definitions

如何安装 @cowprotocol/sdk-app-data?

在项目目录运行 npm install @cowprotocol/sdk-app-data,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ajv(^8.x)、multiformats(^9.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cowprotocol/sdk-app-data 支持 TypeScript 吗?

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

@cowprotocol/sdk-app-data 支持 ESM 还是 CommonJS?

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

@cowprotocol/sdk-app-data 可以商用吗?

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

@cowprotocol/sdk-app-data 的下载量有多少?

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

@cowprotocol/sdk-app-data 还在维护吗?

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