TypeScript Client Example
Use the Fairseq REST API from a TypeScript service.
This example uses the Fairseq REST API directly to create and verify a proof. No SDK package is required.
Direct API Usage
TYPESCRIPT
// Direct API usage (no SDK required)
const FAIRSEQ_API_KEY = process.env.FAIRSEQ_API_KEY!;
const API_BASE = 'https://api.fairseq.io/v1';
async function createProof(transactions: { hash: string; timestamp: number }[]) {
const response = await fetch(`${API_BASE}/proofs`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${FAIRSEQ_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ transactions }),
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
return response.json();
}
async function verifyProof(proofId: string) {
const response = await fetch(`${API_BASE}/verify`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${FAIRSEQ_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ proof_id: proofId }),
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
return response.json();
}Full example
TYPESCRIPT
async function main() {
// Create a proof
const { proof } = await createProof([
{ hash: '0xabc...', timestamp: Date.now() },
{ hash: '0xdef...', timestamp: Date.now() + 100 },
]);
console.log('Proof ID:', proof.id);
// Verify the proof
const verification = await verifyProof(proof.id);
console.log('Valid:', verification.valid);
}
main().catch(console.error);Expected output
TEXT
Proof ID: 550e8400-e29b-41d4-a716-446655440000
Valid: trueNote
For performance-critical systems processing high volumes, consider using the Rust SDK which offers lower latency and native async support.
Was this page helpful? /
Back to docs