Blockia Agent SDK
The Blockia Agent SDK provides a TypeScript/JavaScript client for interacting with the Blockia Pay API and automating ERC-3009 payments. It is designed for developers building payment bots, integrations, and automation tools.
Installation
npm install @blockia-pay/blockia-agent-sdk
Features
- Fetch payment requirements for a pay link (EIP-402/X402)
- Create and sign ERC-3009 payment payloads
- Submit payments to the Blockia API
- Query token balances
- Select payment requirements by network, asset, or scheme
- Full TypeScript types and error handling
Quick Start Example
import { BlockiaAgent } from '@blockia-pay/blockia-agent-sdk';
const agent = new BlockiaAgent({
privateKey: '0xYOUR_PRIVATE_KEY',
apiUrl: 'https://api.blockia.pay/v1',
chainId: 84532, // Base Sepolia
});
// Fetch payment requirements for a link
const requirementsResponse = await agent.getPaymentLinkInfo('LINK_ID');
// Make a payment (convenience method)
const result = await agent.makePayment(requirementsResponse.accepts);
if (result.success) {
console.log('Payment successful! Tx:', result.txHash);
} else {
console.error('Payment failed:', result.error);
}
API Reference
BlockiaAgent Class
Constructor
new BlockiaAgent(config: BlockiaAgentConfig)
privateKey: Signer private key (hex string)apiUrl: Blockia API base URLchainId: EVM chain ID (e.g., 84532 for Base Sepolia)
Methods
getSignerAddress(): string— Returns the signer's addressgetBalance(tokenAddress, ownerAddress): Promise<BalanceResponse>— Get token balancegetPaymentLinkInfo(linkId): Promise<PaymentRequirementsResponse>— Fetch payment requirements for a pay linkmakePayment(requirements: PaymentRequirements[]): Promise<PaymentResponse>— Convenience: select, sign, and submit paymentcreatePaymentPayload(requirement: PaymentRequirements): Promise<ERC3009Payload>— Create a signed ERC-3009 payloadsubmitPayment(requirement, payload): Promise<PaymentResponse>— Submit a signed paymentselectPaymentRequirement(requirements, options): Promise<PaymentRequirements>— Select a requirement by network, asset, or scheme
See types.ts for all type definitions.
Example: Simple Payment Script
import { BlockiaAgent } from '@blockia-pay/blockia-agent-sdk';
const agent = new BlockiaAgent({
privateKey: '0xYOUR_PRIVATE_KEY',
apiUrl: 'http://localhost:3000/',
chainId: 84532,
});
const requirementsResponse = await agent.getPaymentLinkInfo('LINK_ID');
const result = await agent.makePayment(requirementsResponse.accepts);
if (result.success) {
console.log('Payment successful! Tx:', result.txHash);
} else {
console.error('Payment failed:', result.error);
}
Error Handling
All errors extend BlockiaError:
ValidationError: Invalid input or insufficient balanceNetworkError: API/network issuesPaymentError: Payment failed
Advanced Usage
- Use
createPaymentPayload()andsubmitPayment()for custom flows - Use
selectPaymentRequirement()to filter requirements by network, asset, or scheme - Supports custom signer implementations via the
ISignerinterface
Supported Networks
- Base Mainnet (8453)
- Base Sepolia (84532)
- See
chain-config.tsfor all supported EVM networks