Skip to content

Latest commit

 

History

History
188 lines (129 loc) · 4.78 KB

File metadata and controls

188 lines (129 loc) · 4.78 KB

Cambrian API TypeScript Client

A clean, modular TypeScript client for interacting with the Cambrian API – a powerful API delivering blockchain and DeFi data across Solana, Base, and other EVM-compatible networks.

This client aims to simplify integration with Cambrian’s data services in modern TypeScript/JavaScript applications.


🚀 Quick Start

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm
  • A Cambrian API key
    → Follow the steps in the official Getting Started tutorial to obtain your key.

A clean, modular TypeScript application for interacting with the Cambrian API - a comprehensive API for blockchain and DeFi data across Solana, Base, and other EVM networks.

🚀 Quick Start

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm
  • Cambrian API key (Get one here)

Installation

  1. Clone and install dependencies:
pnpm install
  1. Set up your API key:

Create a .env file in the project root:

CAMBRIAN_API_KEY=your-api-key-here
# Optional: Override base URL
# CAMBRIAN_BASE_URL=https://opabinia.cambrian.network

📁 Project Structure

workshop-ufsc/
├── src/
│   ├── client/
│   │   ├── cambrian-client.ts    # Core API client
│   │   └── types.ts               # TypeScript types
│   ├── examples/
│   │   ├── solana/
│   │   │   ├── latest-block.ts   # Get latest Solana block
│   │   │   └── price-current.ts  # Get token price
│   │   └── evm/
│   │       ├── evm-chains.ts              # List supported chains
│   │       ├── uniswap-v3-pools.ts        # List Uniswap V3 pools
│   │       └── uniswap-v3-pool-detail.ts  # Get pool details
│   └── utils/
│       └── env.ts                 # Environment utilities
├── .env                           # Your API key (create this)
├── package.json
└── tsconfig.json

🎯 Usage Examples

Solana Examples

Get Latest Block

pnpm tsx src/examples/solana/latest-block.ts

Get Token Price

pnpm tsx src/examples/solana/price-current.ts So11111111111111111111111111111111111111112

EVM Examples

List Supported Chains

pnpm tsx src/examples/evm/evm-chains.ts

Get Uniswap V3 Pools

# Get first 10 pools (default)
pnpm tsx src/examples/evm/uniswap-v3-pools.ts

# Get pools on Base chain
pnpm tsx src/examples/evm/uniswap-v3-pools.ts base 20

# Get pools on Ethereum
pnpm tsx src/examples/evm/uniswap-v3-pools.ts ethereum 10

Get Specific Pool Details

pnpm tsx src/examples/evm/uniswap-v3-pool-detail.ts 0x... base

💻 Using the Client Programmatically

You can import and use the client in your own TypeScript code:

import { createClient } from "./src/client/cambrian-client";

async function example() {
  const client = createClient("your-api-key");
  
  // Solana
  const block = await client.getLatestBlock();
  const price = await client.getCurrentPrice("So111...");
  
  // EVM
  const chains = await client.getEvmChains();
  const pools = await client.getUniswapV3Pools({ chain: "base", limit: 10 });
  const pool = await client.getUniswapV3Pool("0x...", "base");
}

🔧 Available Client Methods

Solana

  • getLatestBlock() - Get latest Solana block
  • getCurrentPrice(address) - Get current token price
  • getTokenDetails(address) - Get detailed token info

EVM

  • getEvmChains() - List supported chains
  • getUniswapV3Pools(params) - List Uniswap V3 pools
  • getUniswapV3Pool(address, chain) - Get specific pool details
  • getEvmPrice(address, chain) - Get token price
  • getEvmTokens(chain, limit?, offset?) - List whitelisted tokens

Advanced

  • getRaw(path, options) - Get raw API response
  • getObjects(path, options) - Get parsed response as objects
  • tabularToObjects(payload) - Convert tabular data to objects

📚 Documentation

🛠️ Development

Type Checking

pnpm typecheck

Watch Mode

pnpm dev

📝 Notes

  • All examples use the modular client from src/client/cambrian-client.ts
  • Easy to extend with new endpoints - just add methods to the client class
  • Type-safe with TypeScript
  • Clean separation of concerns (client, examples, utilities)

🤝 Support

For questions or issues, visit the Cambrian Discord

📄 License

MIT