Skip to main content

Overview

The MetadataApi 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
Throws an error if the version doesn’t exist.

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

The legacy property provides deprecated methods for backward compatibility.

legacy.fetchDocFromCid

Deprecated. Use fetchDocFromAppDataHex instead.

legacy.uploadMetadataDocToIpfs

Deprecated. IPFS upload functionality is no longer actively maintained.

legacy.appDataToCid

Deprecated. Use getAppDataInfo instead.

legacy.appDataHexToCid

Deprecated. Uses old IPFS CID hashing algorithm.

legacy.fetchDocFromAppDataHex

Deprecated. Uses old IPFS CID format.

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 schema
  • v0.2.0 - Added quote metadata
  • v0.3.0 - Added referrer support
  • v0.4.0 - Added order class
  • …
  • v1.14.0 - Latest (includes hooks, partner fees, etc.)

Type Definitions

Error Handling

Best Practices

  1. Always validate - Use validateAppDataDoc before using app-data
  2. Use latest version - Let generateAppDataDoc pick the latest schema
  3. Cache app-data - Reuse appDataHex for identical metadata
  4. Include referrer - Track order sources with referrer metadata
  5. Document hooks - Clearly document any hooks for security audits

See Also