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 providerconst provider = new ethers.providers.JsonRpcProvider('https://mainnet.base.org');// Create contract instancesconst orchestrator = new ethers.Contract( base.Orchestrator, Orchestrator, provider);const escrow = new ethers.Contract( base.Escrow, Escrow, provider);// Use protocol constantsconsole.log('USDC Address:', USDC);console.log('Intent Expiration:', INTENT_EXPIRATION_PERIOD);
The package uses subpath exports for clean, tree-shakeable imports:
// Network-specific importsimport { 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 importsimport { getKeccak256Hash, calculateIntentHash } from '@zkp2p/contracts-v2/utils/protocolUtils';// Type importsimport type { Escrow, Orchestrator } from '@zkp2p/contracts-v2/types';
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;
The package includes React Native-specific exports:
// These automatically resolve to the correct format for React Nativeimport { base } from '@zkp2p/contracts-v2/addresses';import { Orchestrator } from '@zkp2p/contracts-v2/abis/base';