TypeScript SDK

Client library for TypeScript and JavaScript applications to interact with ERC-1066-x402 gateway.

Installation

npm install @hyperkit/erc1066-x402-sdk

Initialization

client.ts
import { ERC1066Client } from '@hyperkit/erc1066-x402-sdk';

// Initialize client with gateway URL
const client = new ERC1066Client('https://gateway.example.com');

Methods

validateIntent

Validates an intent without executing it

Terminal
const result = await client.validateIntent(intent, chainId);

// Returns:
{
  status: '0x01',  // Status code
  httpCode: 200,   // HTTP status code
  intentHash: '0x...'
}

executeIntent

Executes a validated intent on-chain

Terminal
const result = await client.executeIntent(intent, chainId);

// Returns execution result

mapStatusToAction

Maps status code to agent action

Terminal
const action = client.mapStatusToAction('0x01');
// Returns: 'execute' | 'request_payment' | 'retry' | 'deny'

Types

types.ts
// Intent type
interface Intent {
  sender: string;
  target: string;
  data: string;
  value: string;
  nonce: string;
  validAfter?: string;
  validBefore?: string;
  policyId: string;
}

// Validation result
interface ValidationResult {
  status: string;
  httpCode: number;
  intentHash: string;
  paymentUrl?: string;
}

Examples

example.ts
import { ERC1066Client } from '@hyperkit/erc1066-x402-sdk';

const client = new ERC1066Client('https://gateway.example.com');

const intent = {
  sender: '0x...',
  target: '0x...',
  data: '0x...',
  value: '0',
  nonce: '0',
  policyId: '0x...'
};

// Validate intent
const result = await client.validateIntent(intent, 133717);

// Map status to action
const action = client.mapStatusToAction(result.status);

// Execute based on action
if (action === 'execute') {
  await client.executeIntent(intent, 133717);
} else if (action === 'request_payment') {
  requestPayment(result.paymentUrl);
}