JavaScript SDK
Integrate Incrypt Oracle into your JavaScript applications with our comprehensive SDK. Built for Node.js, React, and browser environments.
Installation
Install the Incrypt Oracle SDK using your preferred package manager:
npm install incrypt-oracle-sdk📋 Requirements
- • Node.js 16.0.0 or higher
- • ethers.js ^6.0.0 (peer dependency)
- • A BSC-compatible wallet or signer for write operations
Quick Start Examples
import { IncryptOracle } from 'incrypt-oracle-sdk';
// Initialize the oracle
const oracle = new IncryptOracle({
network: 'bsc-mainnet',
rpcUrl: 'https://bsc-dataseed1.binance.org/'
});
// Get latest price
const btcPrice = await oracle.getPrice('BTC/USD');
console.log(`BTC: $${btcPrice.value}`);API Reference
constructor(config)
Initialize the Oracle SDK instance
Parameters:
config.network(string)*Network identifier (bsc-mainnet, bsc-testnet)
config.rpcUrl(string)Custom RPC endpoint URL
config.contractAddress(string)Custom oracle contract address
config.signer(Signer)Ethers.js signer for write operations
Returns:
IncryptOracle instancegetPrice(feedId)
Get the latest price for a specific data feed
Parameters:
feedId(string)*Data feed identifier (e.g., "BTC/USD")
Returns:
Promise<PriceData>Example:
const btcPrice = await oracle.getPrice("BTC/USD");subscribe(feedId, callbacks)
Subscribe to real-time updates for a data feed
Parameters:
feedId(string)*Data feed identifier
callbacks.onData(function)*Callback for data updates
callbacks.onError(function)Callback for errors
Returns:
Subscription object with unsubscribe methodExample:
const sub = oracle.subscribe("ETH/USD", { onData: console.log });getAllFeeds()
Get list of all available data feeds
Returns:
Promise<DataFeed[]>Example:
const feeds = await oracle.getAllFeeds();getValidator(address)
Get validator information by address
Parameters:
address(string)*Validator wallet address
Returns:
Promise<ValidatorInfo>Example:
const validator = await oracle.getValidator("0x...");TypeScript Support
The Incrypt Oracle SDK includes comprehensive TypeScript definitions for better development experience.
interface PriceData {
value: number;
confidence: number;
timestamp: number;
feedId: string;
}
interface OracleConfig {
network: 'bsc-mainnet' | 'bsc-testnet';
rpcUrl?: string;
contractAddress?: string;
signer?: ethers.Signer;
}
declare class IncryptOracle {
constructor(config: OracleConfig);
getPrice(feedId: string): Promise<PriceData>;
subscribe(feedId: string, callbacks: SubscriptionCallbacks): Subscription;
getAllFeeds(): Promise<DataFeed[]>;
}Error Handling
The SDK provides comprehensive error handling with specific error types for different scenarios.
NetworkError
RPC connection issues or network problems
catch (error) { if (error instanceof NetworkError) ... }ContractError
Smart contract execution failures
Contract not found or method revertedDataError
Invalid or stale oracle data
Data confidence below thresholdValidationError
Invalid parameters or configuration
Invalid feed ID or network configurationNeed Help?
Join our developer community and get support from our team and other developers.