0.0.1 • Published 6 months ago

@zerodev/cab-sdk v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

@zerodev/cab-sdk

Chain Abstraction SDK for ZeroDev, built on top of @zerodev/sdk.

Installation

bun add @zerodev/cab-sdk

Usage

import { createCabClient } from '@zerodev/cab-sdk'
import { mainnet } from 'viem/chains'

const client = createCabClient({
  chain: mainnet,
  bundlerTransport: http(),
  // Optional transports
  intentTransport: http(),
  relayerTransport: http(),
})

// Flow 1: Direct send
const result1 = await client.sendUserIntent({
  calls: [{
    to: '0x...',
    value: 0n,
    data: '0x...'
  }],
  inputTokens: [{
    address: '0x...',
    chainId: 1
  }],
  outputTokens: [{
    address: '0x...',
    amount: 900000n,
    chainId: 10
  }]
})

// Flow 2: Prepare then send
// First prepare the intent
const intent = await client.prepareUserIntent({
  calls: [{
    to: '0x...',
    value: 0n,
    data: '0x...'
  }],
  inputTokens: [{
    address: '0x...',
    chainId: 1
  }],
  outputTokens: [{
    address: '0x...',
    amount: 900000n,
    chainId: 10
  }]
})

// Then send the prepared intent
const result2 = await client.sendUserIntent({
  intent
})

// Wait for the intent to be opened (works for both flows)
const openReceipt = await client.waitForUserIntentOpenReceipt({
  uiHash: result1.uiHash, // or result2.uiHash
});

// Wait for the intent to be executed (works for both flows)
const executionReceipt = await client.waitForUserIntentExecutionReceipt({
  uiHash: result1.uiHash, // or result2.uiHash
});

Features

  • Extends ZeroDev's KernelClient with chain abstraction capabilities
  • Cross-chain user intent preparation and execution
    • Direct send flow
    • Prepare-then-send flow
  • Intent status tracking
  • Type-safe API
  • Built with Bun and TypeScript

Development

# Install dependencies
bun install

# Build
bun run build

# Test
bun test

# Lint
bun run lint

# Format
bun run format

License

MIT

0.0.1

6 months ago