@br1j/lattice-sdk
v0.1.0
Published
JavaScript/TypeScript SDK for Lattice AI blockchain platform
Maintainers
Readme
Lattice JavaScript/TypeScript SDK
The official JavaScript/TypeScript SDK for the Lattice AI blockchain platform. This SDK provides a comprehensive interface for interacting with Lattice nodes, deploying AI models, managing accounts, and executing transactions.
Installation
npm install @br1j/lattice-sdkQuick Start
import { LatticeSDK } from '@br1j/lattice-sdk';
// Initialize the SDK
const sdk = new LatticeSDK({
nodeUrl: 'https://rpc.br1j.xyz', // Lattice V3 Testnet
chainId: 1337,
});
// Connect to a wallet
await sdk.account.connectWallet();
// Get account balance
const balance = await sdk.account.getBalance();
console.log(`Balance: ${balance} LAT`);
// Deploy a model
const modelId = await sdk.models.deploy({
name: 'My AI Model',
description: 'A simple classification model',
ipfsHash: 'QmYourModelHash',
framework: 'pytorch',
version: '1.0.0',
});
console.log(`Model deployed with ID: ${modelId}`);Features
🔗 Node Connectivity
- Connect to Lattice nodes via RPC/WebSocket
- Real-time event listening
- Automatic reconnection handling
🤖 AI Model Management
- Deploy models to the blockchain
- Execute model inference
- Model versioning and metadata
- IPFS integration for model storage
💰 Account Management
- Wallet integration (MetaMask, WalletConnect)
- Account creation and import
- Balance queries
- Transaction signing
🔄 Transaction Management
- Send transactions
- Smart contract interaction
- Gas estimation
- Transaction status tracking
📊 DAG Explorer
- Query block DAG structure
- Get block information
- Explore transaction history
- Real-time chain updates
API Reference
LatticeSDK
Main SDK class that provides access to all functionality.
const sdk = new LatticeSDK({
nodeUrl: string,
chainId?: number,
timeout?: number,
retries?: number,
});Models
Model deployment and management.
// Deploy a new model
await sdk.models.deploy({
name: string,
description: string,
ipfsHash: string,
framework: 'pytorch' | 'tensorflow' | 'onnx',
version: string,
accessType: 'public' | 'private',
price?: string,
});
// Execute model inference
const result = await sdk.models.execute(modelId, {
inputs: any[],
outputFormat: 'json' | 'binary',
});
// Get model information
const modelInfo = await sdk.models.getInfo(modelId);Accounts
Account and wallet management.
// Connect wallet
await sdk.account.connectWallet();
// Create new account
const account = await sdk.account.create();
// Get balance
const balance = await sdk.account.getBalance(address?);
// Send transaction
const txHash = await sdk.account.sendTransaction({
to: string,
value: string,
data?: string,
gasLimit?: number,
});Contracts
Smart contract interaction.
// Deploy contract
const contractAddress = await sdk.contracts.deploy({
bytecode: string,
abi: any[],
constructorArgs?: any[],
});
// Call contract method
const result = await sdk.contracts.call({
address: string,
abi: any[],
method: string,
args: any[],
});
// Send contract transaction
const txHash = await sdk.contracts.send({
address: string,
abi: any[],
method: string,
args: any[],
value?: string,
});Advanced Usage
Event Listening
// Listen for new blocks
sdk.on('block', (block) => {
console.log(`New block: ${block.hash}`);
});
// Listen for model deployments
sdk.on('modelDeployed', (event) => {
console.log(`Model deployed: ${event.modelId}`);
});
// Listen for transactions
sdk.on('transaction', (tx) => {
console.log(`Transaction: ${tx.hash}`);
});Custom Providers
import { ethers } from 'ethers';
// Use custom provider
const provider = new ethers.providers.WebSocketProvider('ws://localhost:8546');
const sdk = new LatticeSDK({
provider,
chainId: 1337,
});Batch Operations
// Batch multiple model executions
const results = await sdk.models.batchExecute([
{ modelId: 'model1', inputs: [1, 2, 3] },
{ modelId: 'model2', inputs: [4, 5, 6] },
]);Configuration
Environment Variables
LATTICE_NODE_URL=https://rpc.br1j.xyz # Lattice V3 Testnet
LATTICE_CHAIN_ID=1337
LATTICE_TIMEOUT=30000
LATTICE_RETRIES=3TypeScript Configuration
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"declaration": true
}
}Error Handling
import { LatticeError, ModelNotFoundError, InsufficientFundsError } from '@br1j/lattice-sdk';
try {
await sdk.models.execute('invalid-model-id', { inputs: [] });
} catch (error) {
if (error instanceof ModelNotFoundError) {
console.log('Model not found');
} else if (error instanceof InsufficientFundsError) {
console.log('Insufficient funds for execution');
} else if (error instanceof LatticeError) {
console.log('Lattice SDK error:', error.message);
} else {
console.log('Unknown error:', error);
}
}Testing
npm test # Run all tests
npm run test:unit # Run unit tests
npm run test:integration # Run integration tests
npm run test:coverage # Run with coverageContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
Apache-2.0 License. See LICENSE for details.
Support
Changelog
See CHANGELOG.md for version history and updates.
