GUIDES / SDKs
Your language. The same API.
Both SDKs use your account API key and shared credits. Version 0.2.0 is published on npm and NuGet, including typed historical-data pages and bounded iterators.
Use a backend environment. Set OPRAIL_API_ORIGIN and OPRAIL_API_KEY as shown in the quickstart. The SDK calls OpRail's HTTP API; no database connection or wallet private key is needed for reads.
TypeScript / Node.js
Install the published package. It includes TypeScript declarations, CommonJS and ESM named-import compatibility. The declared Node.js minimum is 18.
npm install @oprail/sdk@0.2.0
View @oprail/sdk 0.2.0 on npm ↗
import { OpRailClient } from '@oprail/sdk';
// Staging: adiri. Production: either enabled network.
const network: 'adiri' | 'mainnet' = 'adiri';
const origin = process.env.OPRAIL_API_ORIGIN!.replace(/\/+$/, '');
const client = new OpRailClient({
apiKey: process.env.OPRAIL_API_KEY!,
baseUrl: `${origin}/${network}`,
enableRetries: false
});
const block = await client.blocks.getLatest();
console.log(block.number);
.NET 10
dotnet add package OpRail.Sdk --version 0.2.0
View OpRail.Sdk 0.2.0 on NuGet ↗. Reuse one client per application and dispose it at shutdown. Keep the trailing network slash in the base URI.
using OpRail.Sdk;
// Staging: adiri. Mainnet requires enabled production.
var network = "adiri";
var origin = Environment.GetEnvironmentVariable(
"OPRAIL_API_ORIGIN")!.TrimEnd('/');
using var client = new OpRailClient(
new Uri($"{origin}/{network}/"),
Environment.GetEnvironmentVariable("OPRAIL_API_KEY")!);
var block = await client.GetLatestBlockAsync();
Console.WriteLine(block.Number);
Historical methods
| TypeScript | .NET |
|---|---|
client.history.getStatus | GetHistoryStatusAsync |
getTransactionsPage | GetAddressTransactionsPageAsync |
getTransfersPage | GetAddressTransfersPageAsync |
getLogsPage | GetLogsPageAsync |
iterateTransactions | EnumerateAddressTransactionsAsync |
See history page queries and cursor continuation. Set OPRAIL_ADDRESS to a real address before these bounded iteration examples; add using OpRail.Sdk.Models; for .NET history query types.
const address = process.env.OPRAIL_ADDRESS!;
for await (const tx of client.history.iterateTransactions(address,
{ fromBlock: 1, toBlock: 10000, limit: 50 },
{ maxPages: 2, maxItems: 100, signal: AbortSignal.timeout(20000) })) {
console.log(tx.hash, tx.value);
}
// using OpRail.Sdk.Models;
var address = Environment.GetEnvironmentVariable("OPRAIL_ADDRESS")!;
using var stop = new CancellationTokenSource(TimeSpan.FromSeconds(20));
await foreach (var tx in client.EnumerateAddressTransactionsAsync(address,
new HistoryQuery { FromBlock = 1, ToBlock = 10000, Limit = 50 },
new HistoryItemIterationOptions(MaxPages: 2, MaxItems: 100), stop.Token))
{
Console.WriteLine($"{tx.Hash}: {tx.Value}");
}
Errors and retries
TypeScript history throws OpRailHistoryError; .NET history throws OpRailHistoryException. Both preserve explicit public history codes. TypeScript accepts AbortSignal; .NET accepts CancellationToken. Neither SDK automatically retries historical requests. TypeScript's optional legacy RPC GET retries are separate; the examples disable them.
SDKs do not select a different network for you, sign transactions or retry signed writes. If you supply your own HTTP policies, keep retries explicit and account for admitted-request billing.