This section provides guided walkthroughs for common use cases, complete with sample code, configuration tips, and best‑practice advice.
Create a Node.js microservice that automatically approves or rejects payments based on fraud and reputation scores.
import express from 'express';
import TetronFun from '@tetronfun/sdk';
const app = express();
app.use(express.json());
const client = new TetronFun({ apiKey: process.env.KEY, apiSecret: process.env.SECRET });
app.post('/submit', async (req, res) => {
const { from, to, amount, currency, network } = req.body;
const result = await client.score({ from_address: from, to_address: to, amount, currency, network });
const action = result.recommendation === 'approve' ? 'approved' : 'rejected';
res.json({ status: action, details: result });
});
app.listen(3000);
2. Integrating with a React Frontend
Overview
Embed real‑time score updates in a React dashboard using WebSocket subscriptions.
Steps
Install ws or browser WebSocket
Authenticate and subscribe to scores channel
Display live updates in a component
Sample Code (React)
import { useEffect, useState } from 'react';
export default function LiveScores() {
const [scores, setScores] = useState([]);
useEffect(() => {
const ws = new WebSocket('wss://api.tetronfun.com/v1/stream');
ws.onopen = () => {
ws.send(JSON.stringify({ action: 'authenticate', apiKey: process.env.REACT_APP_KEY }));
ws.send(JSON.stringify({ action: 'subscribe', channels: ['scores'] }));
};
ws.onmessage = evt => {
const msg = JSON.parse(evt.data);
setScores(prev => [msg.data, ...prev].slice(0, 10));
};
return () => ws.close();
}, []);
return (
<ul>
{scores.map(s => (
<li key={s.transaction_id}>
{s.transaction_id}: Fraud {s.fraud_score}, Rep {s.reputation_score}
</li>
))}
</ul>
);
}