Overview
TheMetadataApi class provides utilities for working with CoW Protocol order metadata (app-data). It handles schema validation, document generation, IPFS hashing, and conversion between different metadata formats.
Installation
Constructor
AbstractProviderAdapter
Provider adapter (ViemAdapter, EthersV5Adapter, or EthersV6Adapter)
Basic Setup
Core Methods
generateAppDataDoc
Generate an app-data document using the latest schema version.AppDataParams
App data parameters
LatestAppDataDocVersion
Generated app-data document with latest version
Example
getAppDataInfo
Calculate app-data information including CID, hex, and content.AnyAppDataDocVersion | string
required
App data document object or JSON string
AppDataInfo
Complete app-data information
- appDataContent - The exact string that gets hashed (keccak256) to produce appDataHex
- appDataHex - The bytes32 value used in CoW Protocol orders
- cid - IPFS identifier for finding the document
Example
validateAppDataDoc
Validate an app-data document against its schema.AnyAppDataDocVersion
required
App data document to validate
object
Validation result
Example
getAppDataSchema
Retrieve app-data schema definition by version.string
required
Schema version (e.g., ‘1.14.0’)
AppDataSchema
JSON schema definition
Example
Conversion Methods
appDataHexToCid
Convert app-data hex to IPFS CID.string
required
App data hex string (bytes32)
string
IPFS Content Identifier
Example
cidToAppDataHex
Convert IPFS CID to app-data hex.string
required
IPFS Content Identifier
string
App data hex string (bytes32)
Example
fetchDocFromAppDataHex
Fetch app-data document from IPFS using app-data hex.string
required
App data hex string
AnyAppDataDocVersion
Retrieved app-data document
Requires the document to be uploaded to IPFS.
Example
Legacy Methods
Thelegacy property provides deprecated methods for backward compatibility.
legacy.fetchDocFromCid
legacy.uploadMetadataDocToIpfs
legacy.appDataToCid
legacy.appDataHexToCid
legacy.fetchDocFromAppDataHex
Common Use Cases
Creating Order with Metadata
Adding Hooks to Orders
Partner Fee Integration
Retrieving Order Metadata
Schema Versions
The SDK supports multiple app-data schema versions. The latest version is automatically used.Available Schemas
v0.1.0- Initial schemav0.2.0- Added quote metadatav0.3.0- Added referrer supportv0.4.0- Added order class- …
v1.14.0- Latest (includes hooks, partner fees, etc.)
Type Definitions
Error Handling
Best Practices
- Always validate - Use
validateAppDataDocbefore using app-data - Use latest version - Let
generateAppDataDocpick the latest schema - Cache app-data - Reuse
appDataHexfor identical metadata - Include referrer - Track order sources with referrer metadata
- Document hooks - Clearly document any hooks for security audits
See Also
- TradingSdk - High-level trading interface
- OrderBookApi - Order book API client
- OrderSigningUtils - Order signing utilities
- App-Data Documentation
- Hooks Documentation