|
| 1 | +# REST API |
| 2 | + |
| 3 | +TxGraph components are designed to work with the **TrustIn graph_explore API**. You can also supply your own data from any source — just map to `TxNode[]` and `TxEdge[]`. |
| 4 | + |
| 5 | +## Authentication |
| 6 | + |
| 7 | +Contact [info@trustin.info](mailto:info@trustin.info) to obtain an API key. |
| 8 | + |
| 9 | +Include the key in all requests: |
| 10 | + |
| 11 | +``` |
| 12 | +X-Api-Key: your_api_key_here |
| 13 | +``` |
| 14 | + |
| 15 | +## Endpoints |
| 16 | + |
| 17 | +### `POST /api/v1/graph_explore` |
| 18 | + |
| 19 | +Explore transaction graph starting from a given address. |
| 20 | + |
| 21 | +**Base URL:** `https://api.trustin.info` |
| 22 | + |
| 23 | +#### Request |
| 24 | + |
| 25 | +```http |
| 26 | +POST /api/v1/graph_explore |
| 27 | +Content-Type: application/json |
| 28 | +X-Api-Key: your_api_key_here |
| 29 | +``` |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", |
| 34 | + "chain": "Ethereum", |
| 35 | + "direction": "out", |
| 36 | + "max_depth": 3, |
| 37 | + "from_date": "2024-01-01", |
| 38 | + "to_date": "2024-12-31" |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +#### Request Parameters |
| 43 | + |
| 44 | +| Parameter | Type | Required | Description | |
| 45 | +|-----------|------|----------|-------------| |
| 46 | +| `address` | `string` | ✅ | Starting blockchain address | |
| 47 | +| `chain` | `'Ethereum' \| 'Tron'` | ✅ | Blockchain network | |
| 48 | +| `direction` | `'in' \| 'out' \| 'all'` | — | Default: `'out'` | |
| 49 | +| `max_depth` | `number` | — | Max hops to trace. Default: `3` | |
| 50 | +| `from_date` | `string` | — | Filter: start date `YYYY-MM-DD` | |
| 51 | +| `to_date` | `string` | — | Filter: end date `YYYY-MM-DD` | |
| 52 | + |
| 53 | +#### Response |
| 54 | + |
| 55 | +```json |
| 56 | +{ |
| 57 | + "success": true, |
| 58 | + "data": { |
| 59 | + "nodes": [ |
| 60 | + { |
| 61 | + "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", |
| 62 | + "depth": 0, |
| 63 | + "is_root": true, |
| 64 | + "risk_level": "low", |
| 65 | + "risk_score": 5, |
| 66 | + "tags": [ |
| 67 | + { |
| 68 | + "name": "Vitalik Buterin", |
| 69 | + "primaryCategory": "Individual" |
| 70 | + } |
| 71 | + ], |
| 72 | + "is_stopped": false |
| 73 | + } |
| 74 | + ], |
| 75 | + "edges": [ |
| 76 | + { |
| 77 | + "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", |
| 78 | + "to": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", |
| 79 | + "formatted_amount": "1,234.56 USDT", |
| 80 | + "amount": 1234.56, |
| 81 | + "token": "USDT", |
| 82 | + "last_timestamp": 1704067200, |
| 83 | + "direction": "out", |
| 84 | + "tx_count": 3 |
| 85 | + } |
| 86 | + ], |
| 87 | + "stats": { |
| 88 | + "total_nodes": 42, |
| 89 | + "total_edges": 38, |
| 90 | + "stopped_nodes": 5 |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +#### Error Response |
| 97 | + |
| 98 | +```json |
| 99 | +{ |
| 100 | + "success": false, |
| 101 | + "error": "Invalid API key", |
| 102 | + "code": 401 |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +## Using the API Client |
| 107 | + |
| 108 | +The `examples/local-demo/src/api.ts` provides a ready-to-use client: |
| 109 | + |
| 110 | +```typescript |
| 111 | +import { exploreGraph } from './api' |
| 112 | + |
| 113 | +const graph = await exploreGraph({ |
| 114 | + address: '0xd8dA6BF...', |
| 115 | + chain: 'Ethereum', |
| 116 | + direction: 'out', |
| 117 | + maxDepth: 3, |
| 118 | + fromDate: '2024-01-01', |
| 119 | +}) |
| 120 | + |
| 121 | +// graph is TxGraph — ready for the components |
| 122 | +``` |
| 123 | + |
| 124 | +## Bring Your Own Data |
| 125 | + |
| 126 | +The components don't require the TrustIn API. Supply any `TxNode[]` and `TxEdge[]` data: |
| 127 | + |
| 128 | +```typescript |
| 129 | +import { GraphExplorer } from '@trustin/txgraph' |
| 130 | +import type { TxNode, TxEdge } from '@trustin/txgraph' |
| 131 | + |
| 132 | +// Your own on-chain data pipeline |
| 133 | +const { nodes, edges } = await myOwnGraphProvider.query(address) |
| 134 | + |
| 135 | +// Map to TxNode / TxEdge format |
| 136 | +const txNodes: TxNode[] = nodes.map(n => ({ |
| 137 | + address: n.addr, |
| 138 | + depth: n.hopCount, |
| 139 | + is_root: n.addr === rootAddress, |
| 140 | + risk_level: mapRisk(n.riskScore), |
| 141 | + tags: n.labels.map(l => ({ name: l })), |
| 142 | + is_stopped: n.isLeaf, |
| 143 | +})) |
| 144 | +``` |
0 commit comments