Skip to content

Othentic-Labs/aleph-api-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aleph API Scripts

Scripts for Aleph Backend API with smart contract integration.

Features

  • Auto-generated TypeScript client from Swagger
  • Manager wallet authentication via Privy
  • Smart contract integration for on-chain data
  • Settlement automation with automatic batch ID fetching

Quick Start

1. Install Dependencies

pnpm install

2. Configure Environment

Copy and configure your environment variables:

cp env.example .env

Edit .env with your values:

# API Configuration
ALEPH_API_URL=http://localhost:3000
ALEPH_TIMEOUT=10000

# Manager Authentication
PRIVATE_KEY_MANAGER=0x...
PRIVY_MANAGER_APP_ID=clxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
SIWE_DOMAIN_MANAGER=your-frontend-domain.com

# Blockchain Configuration
RPC_URL=https://rpc.sepolia.ethpandaops.io

# Settlement Configuration (format: <chainId>_<vaultAddress>)
VAULT_ID=11155111_0x1234567890123456789012345678901234567890
CLASS_ID=1

3. Generate API Client

Generate the TypeScript client from your backend's Swagger spec:

pnpm run generate

This fetches ${ALEPH_API_URL}/swagger.json and generates the client to src/generated/backend-client/.

4. Test Authentication

Run the authentication example:

pnpm run example

Expected output:

🚀 Aleph API Scripts - Manager Authentication Example

📋 Step 1: Checking API health...
✅ Health check passed

📋 Step 2: Authenticating as manager...
✅ Authentication successful!

📋 Step 3: Calling protected API endpoint...
✅ Manager identified: { ... }

✅ Example completed successfully!

5. Run Settlement

Execute settlement with NAV (batch ID fetched automatically from blockchain):

pnpm run settle-deposit 1000000.5

What happens:

  1. Parses VAULT_ID to extract chain ID and vault address
  2. Fetches current batch ID from vault contract on-chain
  3. Authenticates with manager wallet
  4. Submits settlement to backend API

Output:

{
  "success": true,
  "message": "Deposit batch settled successfully",
  "batchId": 2
}

Available Scripts

pnpm run generate          # Generate API client from Swagger
pnpm run example           # Test authentication
pnpm run settle-deposit    # Run settlement (requires <nav> argument)
pnpm run build             # Build TypeScript
pnpm run dev               # Watch mode

Environment Variables

Variable Required Description
ALEPH_API_URL Yes Backend API URL
PRIVATE_KEY_MANAGER Yes Manager wallet private key
PRIVY_MANAGER_APP_ID Yes Privy app ID for managers
SIWE_DOMAIN_MANAGER Yes Frontend domain for SIWE
RPC_URL Yes* Blockchain RPC endpoint (*for settlement)
VAULT_ID Yes* Format: <chainId>_<vaultAddress> (*for settlement)
CLASS_ID Yes* Vault class ID (*for settlement)

Troubleshooting

Authentication fails

  • Verify private key is correct
  • Check Privy App ID matches your configuration
  • Ensure SIWE domain matches your frontend

Client generation fails

  • Backend server must be running
  • Swagger must be accessible at ${ALEPH_API_URL}/swagger.json
  • Check .env file has ALEPH_API_URL set

Settlement fails

  • Verify VAULT_ID format: <chainId>_<vaultAddress>
  • Ensure RPC_URL is accessible
  • Check vault address is correct
  • Confirm manager wallet has permissions

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published