JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18
  • Score
    100M100P100Q53189F
  • License MIT

Beginner-friendly SDK for ProofRails ISO 20022 Middleware - Create blockchain-verifiable payment receipts with zero coding knowledge

Package Exports

  • @proofrails/sdk
  • @proofrails/sdk/react

Readme

ProofRails SDK> Beginner-friendly SDK for creating blockchain-verifiable ISO 20022 payment receiptsCreate compliant, auditable payment receipts with just a few lines of code. No blockchain expertise required!## Features- Zero coding knowledge required - Use simple templates- ISO 20022 compliant - Generates standard banking messages- Blockchain-verified - Receipts anchored on Flare blockchain- Tamper-proof - Cryptographic evidence bundles- Real-time updates - Live receipt status via SSE- Works everywhere - TypeScript, JavaScript, Node.js, browsers## Installationbashnpm install @proofrails/sdk# oryarn add @proofrails/sdk## Quick Start### Option 1: Create New Project (Easiest)javascriptimport ProofRails from '@proofrails/sdk';// Create a new project automaticallyconst { client, apiKey, projectId } = await ProofRails.createProject({ label: 'My App'});console.log('Your API Key:', apiKey); // Save this!console.log('Your Project ID:', projectId);### Option 2: Use Existing API Keyjavascriptimport ProofRails from '@proofrails/sdk';const proofrails = new ProofRails({ apiKey: 'your-api-key-here'});## Templates (Beginner-Friendly)### Payment Receiptjavascriptconst receipt = await proofrails.templates.payment({ amount: 100, from: 'Alice', to: 'Bob', purpose: 'Freelance web development', transactionHash: '0x123...'});console.log('Receipt ID:', receipt.id);console.log('Status:', receipt.status);### Donation Receiptjavascriptconst receipt = await proofrails.templates.donation({ amount: 50, donor: 'John Doe', organization: 'Red Cross', campaign: 'Disaster Relief 2024', transactionHash: '0x456...'});### Escrow Releasejavascriptconst receipt = await proofrails.templates.escrow({ amount: 1000, buyer: 'Alice', seller: 'Bob', escrowId: 'ESC-2024-001', releaseReason: 'Milestone 1 completed', transactionHash: '0x789...'});### Grant Disbursementjavascriptconst receipt = await proofrails.templates.grant({ amount: 5000, grantee: 'Research Lab', grantor: 'Science Foundation', grantId: 'GR-2024-001', purpose: 'Climate change research', transactionHash: '0xabc...'});### Refundjavascriptconst receipt = await proofrails.templates.refund({ amount: 25, originalPayment: 'receipt-id-123', reason: 'Product returned', customer: 'Jane Smith', transactionHash: '0xdef...'});## Core Operations### Get Receiptjavascriptconst receipt = await proofrails.receipts.get('receipt-id');console.log(receipt.status); // 'pending' or 'anchored'console.log(receipt.amount);console.log(receipt.anchorTx); // Blockchain transaction (if anchored)### List Receiptsjavascriptconst { items, total } = await proofrails.receipts.list({ limit: 10, status: 'anchored'});items.forEach(receipt => { console.log(receipt.id, receipt.amount);});### Download Artifactsjavascriptconst artifacts = await proofrails.receipts.getArtifacts('receipt-id');console.log('ISO XML:', artifacts.pain001Url);console.log('Bundle:', artifacts.bundleUrl);console.log('Manifest:', artifacts.manifestUrl);## Verification### Verify Receiptjavascriptconst verification = await proofrails.verify.byReceiptId('receipt-id');if (verification.valid && verification.onChain) { console.log(' Receipt is valid and on-chain!'); console.log('Anchor TX:', verification.anchorTx);}### Verify by Bundle Hashjavascriptconst verification = await proofrails.verify.byHash('0x123...');### Get Verification Proofjavascriptconst proof = await proofrails.verify.getProof('receipt-id');console.log('Bundle Hash:', proof.bundleHash);console.log('Block Number:', proof.blockNumber);console.log('Timestamp:', proof.timestamp);## Live Updatesjavascript// Listen to receipt status changes in real-timeconst listener = proofrails.events.listen('receipt-id', (update) => { console.log('Status:', update.status); if (update.status === 'anchored') { console.log('Receipt is now on-chain!'); console.log('Anchor TX:', update.anchorTx); listener.stop(); // Stop listening }});## Embeddable Widgets### Generate Widgetjavascriptconst widget = proofrails.embed.widget('receipt-id', { theme: 'light', width: '100%', height: '400px'});// Use in HTMLdocument.getElementById('receipt').innerHTML = widget.iframeHtml;### Full Page URLjavascriptconst pageUrl = proofrails.embed.fullPage('receipt-id');// https://middleware.com/receipt/receipt-id## Statements### Generate Intraday Statementjavascriptconst statement = await proofrails.statements.intraday({ dateFrom: '2024-01-01', dateTo: '2024-01-31', accountId: 'my-account'});console.log('Download:', statement.downloadUrl);### Generate End-of-Day Statementjavascriptconst statement = await proofrails.statements.endOfDay({ dateTo: '2024-01-31', accountId: 'my-account'});## Project Management### Get Project Infojavascriptconst info = await proofrails.project.getInfo();console.log('Project ID:', info.projectId);### Rotate API Keyjavascriptconst newKey = await proofrails.project.rotateKey();console.log('New API Key:', newKey.apiKey); // Save this!// Update client with new keyproofrails.setApiKey(newKey.apiKey);## Admin Operationsjavascriptconst admin = new ProofRails({ adminToken: 'your-admin-token' });// Create API key for specific projectconst key = await admin.admin.createKey({ projectId: 'proj-123', label: 'Production Key'}); label: 'Production Key'});// Delete API keyawait admin.admin.deleteKey('key-id');## Networksjavascript// Testnet (default)const proofrails = new ProofRails({ apiKey: 'your-key', network: 'coston2'});// Mainnetconst proofrails = new ProofRails({ apiKey: 'your-key', network: 'flare'});## Advanced Configurationjavascriptconst proofrails = new ProofRails({ apiKey: 'your-key', network: 'coston2', baseUrl: 'https://custom-middleware.com', // Optional timeout: 60000 // Request timeout in ms (default: 30000)});## React Hooks (New!)The SDK exports dedicated React hooks for the easiest integration experience.### Setuptypescriptimport { useProofRails } from '@proofrails/sdk/react';// Initialize the hookconst sdk = useProofRails({ apiKey: 'your-api-key' });### Sending Payments (Zero Boilerplate)typescriptimport { useProofRailsPayment } from '@proofrails/sdk/react';const { send, loading, receipt, status } = useProofRailsPayment(sdk);const handleMyButton = async () => { await send({ amount: "10.0", to: "0xReceiverAddress...", purpose: "Payment for Services" });};### Self-Serve Project Creationtypescriptimport { useCreateProject } from '@proofrails/sdk/react';const { create, loading } = useCreateProject();const setup = async () => { const { apiKey, projectId } = await create("My New dApp"); console.log("My new key:", apiKey);};## TypeScript SupportFull TypeScript support with type definitions included:typescriptimport ProofRails, { Receipt, VerificationResult } from '@proofrails/sdk';const proofrails = new ProofRails({ apiKey: 'your-key' });const receipt: Receipt = await proofrails.templates.payment({ amount: 100, from: 'Alice', to: 'Bob', purpose: 'Payment', transactionHash: '0x123...'});const verification: VerificationResult = await proofrails.verify.byReceiptId(receipt.id);## JavaScript (No TypeScript)Works perfectly in plain JavaScript too:javascriptconst ProofRails = require('@proofrails/sdk');const proofrails = new ProofRails({ apiKey: 'your-key' });// Same API, no types needed!## Error Handlingjavascriptimport { ProofRailsError } from '@proofrails/sdk';try { const receipt = await proofrails.receipts.get('invalid-id');} catch (error) { if (error instanceof ProofRailsError) { console.error('Error:', error.message); console.error('Code:', error.code); console.error('Status:', error.statusCode); }}## LicenseMIT## Support- Documentation: docs.proofrails.com- Issues: GitHub Issues- Email: support@proofrails.com---Made with ❤️ by ProofRails# Proofrails-sdk