Skip to main content
This guide covers the basic setup for using the @zkp2p/contracts-v2 package in your TypeScript/JavaScript project.

Quick Start

Here’s a complete example of setting up contract instances:
import { ethers } from 'ethers';
import { base } from '@zkp2p/contracts-v2/addresses';
import { Orchestrator, Escrow } from '@zkp2p/contracts-v2/abis/base';
import { USDC, INTENT_EXPIRATION_PERIOD } from '@zkp2p/contracts-v2/constants/base';

// Set up provider
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.base.org');

// Create contract instances
const orchestrator = new ethers.Contract(
  base.Orchestrator,
  Orchestrator,
  provider
);

const escrow = new ethers.Contract(
  base.Escrow,
  Escrow,
  provider
);

// Use protocol constants
console.log('USDC Address:', USDC);
console.log('Intent Expiration:', INTENT_EXPIRATION_PERIOD);

Module Structure

The package uses subpath exports for clean, tree-shakeable imports:
// Network-specific imports
import { base, baseSepolia } from '@zkp2p/contracts-v2/addresses';
import { Orchestrator } from '@zkp2p/contracts-v2/abis/base';
import { USDC } from '@zkp2p/contracts-v2/constants/base';
import { base as paymentMethods } from '@zkp2p/contracts-v2/paymentMethods';

// Utility imports
import { getKeccak256Hash, calculateIntentHash } from '@zkp2p/contracts-v2/utils/protocolUtils';

// Type imports
import type { Escrow, Orchestrator } from '@zkp2p/contracts-v2/types';

TypeScript Configuration

For optimal TypeScript support, ensure your tsconfig.json includes:
tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "strict": true
  }
}

Working with Different Networks

The package supports multiple networks. Import network-specific modules:
import { base } from '@zkp2p/contracts-v2/addresses';
import * as baseAbis from '@zkp2p/contracts-v2/abis/base';
import * as baseConstants from '@zkp2p/contracts-v2/constants/base';

const orchestratorAddress = base.Orchestrator;
const orchestratorABI = baseAbis.Orchestrator;

ESM vs CommonJS

The package supports both ESM and CommonJS:
import { base } from '@zkp2p/contracts-v2/addresses';
import { Orchestrator } from '@zkp2p/contracts-v2/abis/base';

React Native Support

The package includes React Native-specific exports:
// These automatically resolve to the correct format for React Native
import { base } from '@zkp2p/contracts-v2/addresses';
import { Orchestrator } from '@zkp2p/contracts-v2/abis/base';

Next Steps

Contract Addresses

Learn how to access contract addresses

ABIs

Work with contract ABIs

Constants

Use protocol constants

Utilities

Use protocol utilities

Build docs developers (and LLMs) love