Tenzro Testnet is live. Get testnet TNZO

API Integration Guide

SDKs for Rust, TypeScript, Python, and Go are under active development. In the meantime, interact with Tenzro Network directly via JSON-RPC endpoints. This guide shows you how to integrate Tenzro using standard HTTP requests.

JSON-RPC Access

Endpoint URL

Testnet RPC: https://rpc.tenzro.network Testnet API: https://api.tenzro.network

Basic Request (curl)

curl -X POST https://rpc.tenzro.network \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1 }'

Basic Request (JavaScript/fetch)

async function callRpc(method, params = []) { const response = await fetch('https://rpc.tenzro.network', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', method, params, id: 1, }), }); const data = await response.json(); return data.result; } // Get block number const blockNumber = await callRpc('eth_blockNumber'); console.log('Block number:', blockNumber); // Get balance const balance = await callRpc('eth_getBalance', [ '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb5', 'latest' ]); console.log('Balance:', balance);

Identity Operations

// Register human identity async function registerIdentity(displayName) { const result = await callRpc('tenzro_registerIdentity', [{ identity_type: 'human', display_name: displayName, }]); console.log('DID:', result.did); console.log('Wallet:', result.wallet_address); return result; } await registerIdentity('Alice'); // Resolve DID const identity = await callRpc('tenzro_resolveIdentity', [ 'did:tenzro:human:550e8400...' ]); console.log('Display name:', identity.display_name); console.log('KYC tier:', identity.kyc_tier);

Model Discovery

// List models const models = await callRpc('tenzro_listModels', [{ category: 'llm', }]); models.forEach(model => { console.log(`${model.name}: ${model.price_per_token} TNZO/token`); }); // Request inference const result = await callRpc('tenzro_requestInference', [{ model_id: 'llama-3-70b', input: 'What is the capital of France?', max_tokens: 100, }]); console.log('Request ID:', result.request_id); console.log('Status:', result.status);

Send Transaction

// Send raw transaction const txHash = await callRpc('eth_sendRawTransaction', [ '0xf86c...' // signed transaction data ]); console.log('Transaction hash:', txHash); // Get transaction receipt const receipt = await callRpc('eth_getTransactionReceipt', [txHash]); if (receipt.status === '0x1') { console.log('Transaction successful'); console.log('Block:', receipt.blockNumber); console.log('Gas used:', receipt.gasUsed); }

Available RPC Methods

Method
getBlockNumber()
getBalance(address, block)
sendRawTransaction(data)
getTransactionReceipt(hash)
getPeerCount()
getNodeInfo()
registerIdentity(params)
resolveIdentity(did)
listModels(filters)
requestInference(params)

Complete Workflow Example

End-to-End Integration

// Helper function for RPC calls async function callRpc(method, params = []) { const response = await fetch('https://rpc.tenzro.network', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', method, params, id: 1, }), }); const data = await response.json(); return data.result; } async function workflow() { // 1. Register identity const identity = await callRpc('tenzro_registerIdentity', [{ identity_type: 'human', display_name: 'Alice', }]); console.log('Registered DID:', identity.did); // 2. List available models const models = await callRpc('tenzro_listModels', [{ category: 'llm' }]); const model = models[0]; console.log('Selected model:', model.name); // 3. Request inference const result = await callRpc('tenzro_requestInference', [{ model_id: model.id, input: 'Explain quantum computing', max_tokens: 200, }]); console.log('Request ID:', result.request_id); console.log('Status:', result.status); } workflow().catch(console.error);

Error Handling

All JSON-RPC responses follow the standard JSON-RPC 2.0 error format:

async function callRpcWithErrorHandling(method, params = []) { try { const response = await fetch('https://rpc.tenzro.network', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', method, params, id: 1, }), }); const data = await response.json(); if (data.error) { console.error('RPC Error:', data.error.message); console.error('Error code:', data.error.code); throw new Error(data.error.message); } return data.result; } catch (error) { console.error('Request failed:', error); throw error; } } // Usage try { const balance = await callRpcWithErrorHandling('eth_getBalance', [ '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb5', 'latest' ]); console.log('Balance:', balance); } catch (error) { console.error('Failed to get balance:', error.message); }