CAIP2

Introduction

CAIP-2 (Chain Agnostic Improvement Proposal 2) provides a standardized format for blockchain network identification. This guide covers the implementation using the @snowballmoney/chain-agnostic-utils library, which simplifies cross-chain development by providing a consistent way to identify and work with different blockchain networks.

Understanding CAIP-2

CAIP-2 addresses a critical challenge in blockchain development: the inconsistent ways different chains identify their networks. For example:

  • Ethereum and EVM chains use numeric IDs (e.g., 1 for mainnet, 5 for goerli)

  • Solana uses cluster names (e.g., mainnet-beta, devnet)

  • Some chains have conflicting IDs (both Ethereum and Aptos use 1 for mainnet)

The CAIP-2 standard solves this by using a consistent format:

namespace:reference

Where:

  • namespace: Identifies the blockchain ecosystem (e.g., 'eip155' for EVM chains, 'solana' for Solana)

  • reference: Network-specific identifier within that ecosystem

Installation

Install the library using npm or yarn:

npm install @snowballmoney/chain-agnostic-utils
# or
yarn add @snowballmoney/chain-agnostic-utils

Basic Usage

Network Identification

Working with Network Metadata

Advanced Usage: CAIP2Manager

The CAIP2Manager provides a flexible way to manage network metadata and combine built-in networks with custom ones.

Parsing CAIP-2 Identifiers

Supported Networks

The library supports a wide range of blockchain networks across different ecosystems:

EVM-based Networks (eip155)

  • Ethereum

  • BNB Smart Chain

  • Polygon

  • Arbitrum

  • Optimism

  • Avalanche

  • Base

  • Linea

Move-based Networks

  • Movement

  • Aptos

  • Sui

Layer 1 Ecosystems

  • Bitcoin (BIP-122)

  • Solana

  • Cardano

  • Polkadot

  • Cosmos

  • NEAR

Layer 2 Solutions

  • StarkNet

  • zkSync

  • Linea

Network Metadata

Each supported network includes comprehensive metadata:

  • Name: Human-readable network name

  • Native Currency: Network's native token symbol

  • Icon URL: Network's icon or logo

  • Explorer URL: Block explorer URL

  • RPC URL: Network RPC endpoint (where applicable)

Best Practices

  1. Always validate CAIP-2 identifiers before using them in your application

  2. Use the CAIP2Manager for consistent network management across your application

  3. Include proper error handling for unsupported networks

  4. Consider caching network metadata for better performance

Contributing

To add support for new networks or update existing network information, please submit a pull request with:

  1. Network identifier following CAIP-2 format

  2. Complete network metadata

  3. Documentation updates if needed

Last updated