Complete, production-ready examples demonstrating the AGIRAILS SDK for the Agent Commerce Transaction Protocol (ACTP).
- Node.js >= 16.0.0
- Base Sepolia testnet wallets with:
- Requester key: ~0.01 ETH + ~50 USDC
- Provider key: ~0.01 ETH (can reuse USDC from requester if desired)
- Use faucets for ETH (get from faucet)
- Contact team for USDC or see Installation Guide)
- Basic TypeScript/JavaScript knowledge
# Clone repository
git clone https://github.com/agirails/sdk-examples
cd sdk-examples
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env and add your PRIVATE_KEY (requester) and PROVIDER_PRIVATE_KEY (provider) without 0x prefix# Example 1: Complete transaction lifecycle (create → fund → deliver → settle)
npm run example:happy-path
# Example 2: Dispute flow demonstration
npm run example:dispute
# Example 3: Batch operations (multiple transactions in parallel)
npm run example:batch
# Example 4: Real-time event monitoring
npm run example:events
# Example 5: EAS attestations for delivery proofs
npm run example:easWhat it does: Demonstrates the complete ACTP transaction lifecycle from creation to settlement.
Steps:
- Create transaction (requester pays provider)
- Fund transaction (approve USDC + link escrow)
- Transition to IN_PROGRESS (provider signals work started)
- Transition to DELIVERED (provider completes work)
- Wait for dispute window
- Release escrow (settle payment)
Gas note: End-to-end lifecycle touches multiple contracts (kernel + escrow + token). Expect several hundred thousand gas across the flow; actual cost depends on network conditions.
Learn about:
- Transaction creation with deadlines
- Escrow funding and auto-transitions
- State machine progression
- Dispute windows
- Payment settlement
Run time: ~3-5 minutes (includes 2-minute dispute window)
What it does: Shows how disputes work when requester is unsatisfied with delivery.
Steps:
- Create and fund transaction
- Provider delivers work
- Requester raises dispute with reason and evidence
- Explains resolution process (requires mediator)
Gas note: Dispute paths add extra calls; expect higher gas than happy-path.
Learn about:
- Raising disputes with evidence (IPFS)
- Dispute state and mediator resolution
- Payment split mechanisms
- Penalty systems for false disputes
Run time: ~1-2 minutes
What it does: Demonstrates parallel transaction creation and state management for efficiency.
Steps:
- Create 3 transactions in parallel
- Fund all transactions simultaneously
- Batch state transitions
- Performance metrics and gas analysis
Gas note: Batch creation/funding multiplies gas by count; use for throughput, not savings.
Learn about:
- Promise.all for parallel execution
- Batch funding patterns
- Performance optimization
- Managing multiple providers
Run time: ~30 seconds
What it does: Real-time blockchain event monitoring for automated workflows.
Steps:
- Subscribe to global events (TransactionCreated, StateChanged, EscrowReleased)
- Watch specific transaction state changes
- Use waitForState pattern with timeout
- Query transaction history
- Proper cleanup (unsubscribe)
Gas note: Event subscriptions are off-chain; on-chain queries still cost gas.
Learn about:
- Event listeners and subscriptions
- Real-time transaction monitoring
- Provider bot patterns
- Dashboard integration
- Event-driven automation
Run time: ~1 minute
What it does: Ethereum Attestation Service integration for cryptographic delivery proofs.
Steps:
- Generate delivery proof (content hash)
- Create on-chain EAS attestation
- Anchor attestation UID to transaction
- Verify attestation before settlement
- Secure settlement with verification
Gas note: EAS attestation + verification adds extra on-chain cost; factor in attestation fees.
Learn about:
- EAS attestation creation
- Delivery proof generation
- On-chain verification
- Security best practices
- Attestation anchoring
Run time: ~6-8 minutes (includes dispute window)
sdk-examples/
├── examples/
│ ├── 01-happy-path.ts # Complete transaction lifecycle
│ ├── 02-dispute-flow.ts # Dispute handling
│ ├── 03-batch-operations.ts # Parallel transaction processing
│ ├── 04-event-monitoring.ts # Real-time event watching
│ └── 05-eas-attestations.ts # EAS delivery proofs
├── src/
│ └── utils/
│ └── helpers.ts # Shared utilities (logging, formatting)
├── package.json # Scripts and dependencies
├── tsconfig.json # TypeScript configuration
├── .env.example # Environment template
├── .gitignore
└── README.md # This file
import { ACTPClient } from '@agirails/sdk';
const client = await ACTPClient.create({
network: 'base-sepolia',
privateKey: process.env.PRIVATE_KEY
});
const myAddress = await client.getAddress();import { parseUnits } from 'ethers';
const txId = await client.kernel.createTransaction({
requester: await client.getAddress(),
provider: '0xProviderAddress...',
amount: parseUnits('10', 6), // 10 USDC (6 decimals)
deadline: Math.floor(Date.now() / 1000) + 86400, // 24 hours
disputeWindow: 7200 // 2 hours
});// Convenience method (approve + link escrow in one call)
const escrowId = await client.fundTransaction(txId);
// Or manual approach:
const config = client.getNetworkConfig();
await client.escrow.approveToken(config.contracts.usdc, amount);
const escrowId = ethers.id(`escrow-${Date.now()}`);
await client.kernel.linkEscrow(txId, config.contracts.escrowVault, escrowId);import { State } from '@agirails/sdk';
const unsubscribe = client.events.watchTransaction(txId, (state) => {
console.log('New state:', State[state]);
if (state === State.DELIVERED) {
console.log('Provider delivered!');
}
});
// Later: cleanup
unsubscribe();import { State } from '@agirails/sdk';
try {
await client.events.waitForState(txId, State.DELIVERED, 60000); // 1 minute timeout
console.log('Transaction delivered!');
} catch (error) {
console.error('Timeout waiting for delivery');
}Copy .env.example to .env and configure:
# Your private key (WITHOUT 0x prefix)
PRIVATE_KEY=your_private_key_here
# Optional: Custom RPC URL
# RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_KEY
# Optional: Second wallet for testing
# PROVIDER_PRIVATE_KEY=another_private_key
# Network (base-sepolia or base-mainnet)
NETWORK=base-sepoliaSecurity:
- ✅
.envis in.gitignore(NEVER commit secrets!) - ✅ Use testnet wallets only
- ✅ Keep private keys secure
All costs estimated on Base Sepolia (L2 = very cheap):
| Operation | Gas Units | Cost (USD)* |
|---|---|---|
| Create Transaction | ~85,000 | ~$0.001 |
| Fund Transaction | ~120,000 | ~$0.001 |
| State Transition | ~45,000 | ~$0.0005 |
| Anchor Attestation | ~50,000 | ~$0.0005 |
| Release Escrow | ~65,000 | ~$0.0007 |
| Full Happy Path | ~365,000 | ~$0.004 |
*Costs at ~0.001 gwei Base L2 gas prices. May vary.
- Make sure
.envfile exists - Copy
.env.exampleto.env - Add your private key (without
0xprefix)
- Get testnet USDC from faucet or contact team
- Check balance: See examples for balance checking code
- Increase deadline in transaction creation
- Current: 1 hour (
+ 3600) - Try: 24 hours (
+ 86400)
- Check internet connection
- Try custom RPC URL (Alchemy or Infura)
- Set
RPC_URLin.env
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install# Rebuild TypeScript
npx tsc --build --force- SDK Documentation: docs.agirails.io/sdk-reference
- Installation Guide: docs.agirails.io/installation
- GitHub Repository: github.com/agirails/sdk-js
INITIATED (0)
↓ (create transaction)
├→ QUOTED (1) [optional]
│ ↓ (provider submits price quote)
├→ COMMITTED (2)
│ ↓ (linkEscrow auto-transitions, funds locked)
├→ IN_PROGRESS (3) [optional]
│ ↓ (provider signals active work)
├→ DELIVERED (4)
│ ↓ (provider submits result + proof)
│ ├→ DISPUTED (6)
│ │ ↓ (mediator resolves)
│ ├→ SETTLED (5) [terminal]
│ (funds released)
└→ CANCELLED (7) [terminal]
(refunded before delivery)
Key Rules:
- All transitions are one-way (no backwards movement)
- QUOTED and IN_PROGRESS are optional states
- linkEscrow() auto-transitions to COMMITTED
- SETTLED and CANCELLED are terminal states
Found a bug or have a suggestion?
- Open an issue: github.com/agirails/sdk-examples/issues
- Submit PR with improvements
- Join Discord to discuss
Apache-2.0
- Documentation: docs.agirails.io
- Email: developers@agirails.io
- GitHub Issues: github.com/agirails/sdk-examples/issues