Installation

Get started with the OP Interop Alerts SDK by installing it in your project.

Requirements

  • • Node.js 18.0.0 or higher
  • • TypeScript 5.0.0 or higher (recommended)
  • • A project using Viem for Ethereum interactions

Package Installation

Install the SDK using your preferred package manager:

npm install @wakeuplabs/op-interop-alerts-sdk

Basic Setup

Here's how to get started with the SDK in your project:

src/monitoring.ts
typescript
import { 
  startTracking, 
  generateMetrics, 
  processAlerts,
  TrackingResult 
} from '@wakeuplabs/op-interop-alerts-sdk';
import { chainsInfoMock } from '@wakeuplabs/op-interop-alerts-sdk/config';

// Define your private keys
const pksInfo = {
  origin: process.env.ORIGIN_PRIVATE_KEY as `0x${string}`,
  destination: process.env.DESTINATION_PRIVATE_KEY as `0x${string}`,
};

// Define tracking callback
const trackingCallback = (result: TrackingResult) => {
  console.log('Tracking result:', result);
  
  if (result.success) {
    console.log('✅ Message tracked successfully');
  } else {
    console.error('❌ Tracking failed:', result.error);
  }
};

// Start monitoring
async function startMonitoring() {
  try {
    await startTracking(
      chainsInfoMock, 
      pksInfo, 
      trackingCallback,
      10 // Check every 10 minutes
    );
  } catch (error) {
    console.error('Failed to start monitoring:', error);
  }
}

startMonitoring();

Contract Deployment

Before using the SDK, you need to deploy MessageReceiver contracts on both your origin and destination chains. The SDK provides convenient functions to handle this deployment process.

Deploy on Both Chains

Use the setupContracts function to deploy on both chains simultaneously:

deploy-contracts.ts
typescript
import { setupContracts } from '@wakeuplabs/op-interop-alerts-sdk';
import { optimismSepolia, baseSepolia } from 'viem/chains';

async function deployContracts() {
  try {
    const result = await setupContracts({
      origin: {
        chain: optimismSepolia,
        rpcUrl: 'https://sepolia.optimism.io',
        privateKey: process.env.ORIGIN_PRIVATE_KEY as `0x${string}`
      },
      destination: {
        chain: baseSepolia,
        rpcUrl: 'https://sepolia.base.org',
        privateKey: process.env.DESTINATION_PRIVATE_KEY as `0x${string}`
      }
    });

    console.log('🎉 Deployment completed!');
    console.log('Origin contract:', result.origin.messageReceiverAddress);
    console.log('Destination contract:', result.destination.messageReceiverAddress);
    
    // Save these addresses for your chain configuration
    return result;
  } catch (error) {
    console.error('❌ Deployment failed:', error);
    throw error;
  }
}

deployContracts();

Deploy Single Contract

For deploying on a single chain, use the deployMessageReceiver function:

import { deployMessageReceiver } from '@wakeuplabs/op-interop-alerts-sdk';
import { optimismSepolia } from 'viem/chains';

const result = await deployMessageReceiver({
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
  chain: optimismSepolia,
  rpcUrl: 'https://sepolia.optimism.io'
});

console.log('Contract deployed at:', result.contractAddress);
console.log('Transaction hash:', result.transactionHash);

Environment Variables

Create a .env file in your project root with the following variables:

.env
bash
# Required: Private keys for origin and destination chains
ORIGIN_PRIVATE_KEY=0x...
DESTINATION_PRIVATE_KEY=0x...

# Optional: Tracking interval in minutes (default: 10)
TRACKING_INTERVAL_MINUTES=10

# Optional: Slack notifications
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
SLACK_CHANNEL=#alerts
SLACK_USERNAME=OP Interop Alerts
SLACK_ICON_EMOJI=:warning:

Security Note: Never commit your private keys to version control. Use environment variables and add .env to your .gitignore file.

Chain Configuration

The SDK comes with pre-configured chain information for testing. You can also define your own chains:

import { chainsInfoMock } from '@wakeuplabs/op-interop-alerts-sdk/config';

// Use the pre-configured chains for testing
console.log('Origin Chain ID:', chainsInfoMock.chainOrigin.chainId);
console.log('Destination Chain ID:', chainsInfoMock.chainDestination.chainId);

Installation Complete!

You've successfully installed the OP Interop Alerts SDK. Now you can explore the different modules: