sdk

package module
v1.16.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

README ΒΆ

Lux SDK

The official Go SDK for building and managing Lux-compatible networks and blockchains. This SDK provides a unified interface integrating the full Lux ecosystem - netrunner for network orchestration, the CLI for user-friendly operations, and direct node APIs for high-performance applications.

🎯 Key Capabilities

The Lux SDK is your complete toolkit for blockchain development, offering:

Network Orchestration
  • Multi-Network Management: Launch and manage mainnet, testnet, or custom local networks
  • Dynamic Scaling: Add/remove nodes on-the-fly with automatic rebalancing
  • Network Simulation: Test network behaviors and consensus under various conditions
  • Performance Testing: Built-in benchmarking and stress testing capabilities
Blockchain Development
  • Multi-Layer Architecture: Build L1 sovereign chains, L2 rollups, or L3 app-specific chains
  • VM Flexibility: Deploy EVM, WASM, or custom VMs with full language support
  • Rapid Prototyping: Go from idea to deployed blockchain in minutes
  • Migration Tools: Seamlessly migrate from subnets to independent L1s
Developer Experience
  • Unified API: Single SDK interface for all Lux operations
  • Smart Defaults: Automatic selection of best method (CLI β†’ netrunner β†’ native)
  • Type Safety: Full Go type safety with comprehensive error handling
  • Extensive Examples: Production-ready code samples for common use cases

Features

  • πŸš€ Network Management: Full netrunner integration for complex network orchestration
  • πŸ”— Blockchain Building: Build L1/L2/L3 chains with any VM type
  • πŸ’° Staking & Validation: Complete P-Chain operations for network security
  • πŸͺ™ Asset Management: Create, trade, and manage assets on X-Chain
  • πŸ“œ Smart Contracts: Deploy and interact with contracts on C-Chain
  • πŸŒ‰ Cross-Chain Operations: Atomic swaps and seamless asset transfers
  • πŸ‘› Wallet Integration: HD wallets, multisig, and hardware wallet support
  • πŸ›‘οΈ Quantum-Resistant: Q-Chain integration for post-quantum cryptography
  • 🌐 WASM Support: Run any language via WebAssembly
  • πŸ”§ CLI Integration: Programmatic access to all CLI commands
  • πŸ“Š Monitoring & Telemetry: Built-in metrics and observability
  • πŸ—οΈ Infrastructure as Code: Define entire networks declaratively

Installation

go get github.com/luxfi/sdk

Quick Start

package main

import (
    "context"
    "log"

    "github.com/luxfi/sdk"
    "github.com/luxfi/sdk/config"
)

func main() {
    // Initialize SDK with auto-detection of available tools
    cfg := config.Default()
    cfg.NodeEndpoint = "http://localhost:9650" // Optional: connect to existing node

    luxSDK, err := sdk.New(cfg)
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    // Launch a network (uses CLI or netrunner automatically)
    network, err := luxSDK.LaunchNetwork(ctx, "local", 5)
    if err != nil {
        log.Fatal(err)
    }

    // Create and deploy blockchain with best available method
    blockchain, err := luxSDK.CreateAndDeployBlockchain(ctx, &sdk.BlockchainParams{
        Name:    "my-chain",
        Type:    blockchain.BlockchainTypeL1,
        VMType:  blockchain.VMTypeEVM,
        Network: network,
    })
    if err != nil {
        log.Fatal(err)
    }

    log.Printf("Blockchain %s deployed on network %s", blockchain.Name, network.Name)
}

πŸ”§ Integrated Tools

The SDK seamlessly integrates with the Lux ecosystem's core tools:

Netrunner Integration

Full network orchestration capabilities:

// Direct netrunner access for advanced scenarios
netrunner := luxSDK.Netrunner()
if netrunner != nil {
    // Start netrunner server
    err := netrunner.StartServer(ctx)

    // Create complex network topology
    network, err := netrunner.CreateNetwork(ctx, "testnet", 11)

    // Deploy blockchain with specific configuration
    err = netrunner.DeployBlockchain(ctx, networkID, &BlockchainSpec{
        Name:   "my-blockchain",
        VMType: "evm",
        Genesis: customGenesis,
    })
}
CLI Wrapper

Programmatic access to all CLI commands:

// Use CLI commands directly
cli := luxSDK.CLI()
if cli != nil {
    // Execute any CLI command
    output, err := cli.Execute(ctx, "network", "status")

    // Type-safe wrappers for common operations
    err = cli.CreateBlockchain(ctx, "my-chain", "evm")
    err = cli.DeployBlockchain(ctx, "my-chain", "local")

    // Key management
    keys, err := cli.ListKeys(ctx)
    key, err := cli.CreateKey(ctx, "validator-key")
}
Node API Client

Direct node communication for high-performance operations:

// Access node APIs directly
node := luxSDK.Node()
if node != nil {
    // Get node information
    info, err := node.GetNodeInfo(ctx)

    // Platform chain operations
    validators, err := node.GetCurrentValidators(ctx, constants.PrimaryNetworkID)

    // Keystore operations
    addresses, err := node.ListAddresses(ctx, "my-user")
}

πŸš€ General-Purpose Use Cases

Infrastructure Automation
// Define infrastructure as code
infrastructure := &NetworkDefinition{
    Networks: []NetworkSpec{
        {Name: "prod-mainnet", Type: "mainnet", Nodes: 21},
        {Name: "staging", Type: "testnet", Nodes: 11},
        {Name: "dev", Type: "local", Nodes: 5},
    },
    Blockchains: []BlockchainSpec{
        {Name: "defi-chain", VM: "evm", Network: "prod-mainnet"},
        {Name: "nft-chain", VM: "evm", Network: "prod-mainnet"},
        {Name: "game-chain", VM: "wasm", Network: "staging"},
    },
}

// Deploy entire infrastructure
deployer := sdk.NewInfrastructureDeployer(luxSDK)
err := deployer.Deploy(ctx, infrastructure)
Multi-Chain DApp Development
// Build cross-chain DApp
dapp := sdk.NewDApp(luxSDK)

// Deploy contracts across multiple chains
contracts := dapp.DeployContracts(ctx, map[string][]byte{
    "c-chain": dexContract,
    "nft-chain": nftContract,
    "game-chain": gameContract,
})

// Set up cross-chain messaging
bridge := dapp.CreateBridge(ctx, []string{"c-chain", "nft-chain", "game-chain"})

// Monitor all chains
monitor := dapp.Monitor(ctx)
for event := range monitor.Events() {
    log.Printf("Chain: %s, Event: %s", event.Chain, event.Type)
}
Network Testing & Simulation
// Create test scenarios
tester := sdk.NewNetworkTester(luxSDK)

// Simulate network partitions
tester.SimulatePartition(ctx, []string{"node1", "node2"}, []string{"node3", "node4", "node5"})

// Test consensus under load
results := tester.StressTest(ctx, &StressTestParams{
    TPS:      10000,
    Duration: 5 * time.Minute,
    Scenario: "high-value-transfers",
})

// Chaos testing
tester.ChaosTest(ctx, &ChaosParams{
    RandomlyKillNodes: true,
    NetworkLatency:    100 * time.Millisecond,
    PacketLoss:        0.1,
})
Enterprise Integration
// Enterprise-grade deployment
enterprise := sdk.NewEnterpriseDeployment(luxSDK)

// Deploy with compliance requirements
chain, err := enterprise.DeployCompliantChain(ctx, &ComplianceParams{
    DataResidency: "US",
    Encryption:    "AES-256",
    AuditLog:      true,
    GDPR:          true,
})

// Set up monitoring and alerting
enterprise.SetupMonitoring(ctx, &MonitoringConfig{
    Prometheus: true,
    Grafana:    true,
    Alerts: []Alert{
        {Type: "node-down", Threshold: 1, Action: "page-oncall"},
        {Type: "high-latency", Threshold: "100ms", Action: "email"},
    },
})

// Generate compliance reports
report := enterprise.GenerateComplianceReport(ctx, time.Now().AddDate(0, -1, 0), time.Now())

Core Components

Network Management

The SDK uses netrunner for comprehensive network management:

// Create a network
network, err := sdk.CreateNetwork(ctx, &network.NetworkParams{
    Name:             "test-network",
    Type:             network.NetworkTypeLocal,
    NumNodes:         5,
    EnableStaking:    true,
    EnableMonitoring: true,
})

// Add nodes
node, err := sdk.AddNode(ctx, network.ID, &network.NodeParams{
    Name:        "validator-01",
    Type:        network.NodeTypeValidator,
    StakeAmount: 2000,
})

// Manage network lifecycle
err = sdk.StartNetwork(ctx, networkID)
err = sdk.StopNetwork(ctx, networkID)
Blockchain Building

Build any type of blockchain on Lux:

// Create L1 (Sovereign Chain)
l1, err := sdk.CreateL1(ctx, "my-l1", &blockchain.L1Params{
    VMType:      blockchain.VMTypeEVM,
    Genesis:     genesisBytes,
    ChainConfig: configBytes,
})

// Create L2 (Based Rollup)
l2, err := sdk.CreateL2(ctx, "my-rollup", &blockchain.L2Params{
    VMType:          blockchain.VMTypeEVM,
    SequencerType:   "centralized",
    DALayer:         "celestia",
    SettlementChain: l1.ID,
})

// Create L3 (App Chain)
l3, err := sdk.CreateL3(ctx, "my-game", &blockchain.L3Params{
    VMType:  blockchain.VMTypeWASM,
    L2Chain: l2.ID,
    AppType: "gaming",
})
Chain Operations
P-Chain (Platform Chain)
// Stake on primary network
txID, err := chainManager.Stake(ctx,
    big.NewInt(2000), // 2000 LUX
    14 * 24 * time.Hour, // 14 days
)

// Delegate to validator
txID, err := chainManager.Delegate(ctx, nodeID, amount, duration)

// Create subnet
subnetID, err := chainManager.P().CreateSubnet(ctx, &CreateSubnetParams{
    ControlKeys: []ids.ShortID{key1, key2},
    Threshold:   2,
})

// Add subnet validator
txID, err := chainManager.P().AddSubnetValidator(ctx, &AddSubnetValidatorParams{
    NodeID:   nodeID,
    SubnetID: subnetID,
    Weight:   100,
})
X-Chain (Exchange Chain)
// Create asset
assetID, err := chainManager.CreateAsset(ctx, "MyToken", "MTK", totalSupply)

// Send asset
txID, err := chainManager.SendAsset(ctx, assetID, amount, recipient)

// Create NFT collection
nftID, err := chainManager.X().CreateNFT(ctx, &CreateNFTParams{
    Name:   "LuxNFT",
    Symbol: "LNFT",
})

// Trade assets
orderID, err := chainManager.TradeAssets(ctx,
    sellAsset, sellAmount,
    buyAsset, buyAmount,
)
C-Chain (Contract Chain)
// Deploy contract
address, txHash, err := chainManager.C().DeployContract(ctx, &DeployContractParams{
    Bytecode: contractBytecode,
    GasLimit: 300000,
})

// Call contract
result, err := chainManager.C().CallContract(ctx, &CallContractParams{
    To:   contractAddress,
    Data: callData,
})

// DeFi operations (coming soon)
txHash, err := chainManager.C().SwapTokens(ctx, &SwapParams{
    TokenIn:  USDC,
    TokenOut: LUX,
    Amount:   amount,
})
Cross-Chain Operations
// Transfer between chains
txID, err := chainManager.TransferCrossChain(ctx, &CrossChainTransferParams{
    SourceChain: "C",
    TargetChain: "P",
    AssetID:     luxAssetID,
    Amount:      amount,
    To:          recipient,
})

// Get balances across all chains
balances, err := chainManager.GetBalance(ctx, address)
for chain, balance := range balances.Chains {
    fmt.Printf("%s-Chain: %s\n", chain, balance)
}
Wallet Management
// Create wallet
wallet, err := chainManager.CreateWallet(ctx, "my-wallet")

// Create multisig wallet
multisig, err := chainManager.CreateMultisigWallet(ctx, "treasury",
    []ids.ShortID{owner1, owner2, owner3},
    2, // threshold
)

// List wallets
wallets, err := chainManager.ListWallets(ctx)

Advanced Features

Custom VM Development
// Create custom VM
vm, err := sdk.CreateVM(ctx, &vm.CreateParams{
    Name:     "MyVM",
    Type:     vm.TypeWASM,
    Runtime:  wasmRuntime,
    Handlers: handlers,
})

// Register VM
err = sdk.RegisterVM(ctx, vm)
High-Performance Features
  • Parallel Processing: Leverage Go's concurrency for parallel operations
  • Batch Operations: Execute multiple operations in a single transaction
  • Connection Pooling: Efficient connection management for high throughput
  • Caching: Built-in caching for frequently accessed data
WASM Support
// Deploy WASM contract
wasmID, err := sdk.DeployWASM(ctx, &WASMDeployParams{
    Code:     wasmBytes,
    InitArgs: initParams,
})

// Execute WASM function
result, err := sdk.ExecuteWASM(ctx, wasmID, "transfer", args)

CLI Integration

The SDK wraps the Lux CLI for seamless command execution:

// Execute any CLI command programmatically
output, err := sdk.ExecuteCommand(ctx, "network", "status")

// Use CLI commands with Go types
result, err := sdk.ExecuteCommand(ctx, "subnet", "create",
    "--control-keys", strings.Join(keys, ","),
    "--threshold", "2",
)

Complete Example

See examples/complete/main.go for a comprehensive example covering:

  • Network creation and management
  • Blockchain deployment (L1/L2/L3)
  • Staking and delegation
  • Asset creation and trading
  • Smart contract deployment
  • Cross-chain transfers

Architecture

The SDK provides a unified interface to the entire Lux ecosystem:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Lux SDK                          β”‚
β”‚         Unified API with Smart Defaults             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              Integration Layer                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚    CLI      β”‚  Netrunner  β”‚    Node     β”‚      β”‚
β”‚  β”‚ Integration β”‚ Integration β”‚    APIs     β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              Core SDK Components                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚   Network   β”‚ Blockchain  β”‚     VM      β”‚      β”‚
β”‚  β”‚   Manager   β”‚   Builder   β”‚   Manager   β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              Chain Operations                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚   P   β”‚   X   β”‚   C   β”‚   M   β”‚   Q   β”‚        β”‚
β”‚  β”‚ Chain β”‚ Chain β”‚ Chain β”‚ Chain β”‚ Chain β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         External Lux Components                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚   luxd/cli  β”‚  netrunner  β”‚ lux/node    β”‚      β”‚
β”‚  β”‚  (wrapper)  β”‚  (network)  β”‚   (APIs)    β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Integration Strategy

The SDK intelligently selects the best available method for each operation:

  1. CLI First: For user-friendly operations with good defaults
  2. Netrunner: For complex network orchestration and testing
  3. Node APIs: For high-performance direct node communication
  4. Built-in: Fallback implementation when external tools unavailable

This ensures your code works in any environment - from development laptops to production clusters.

🏭 Production Deployment

Mainnet Launch
// Production deployment with monitoring
prod := sdk.NewProductionDeployment(luxSDK)

// Deploy mainnet with 21 validators
mainnet, err := prod.LaunchMainnet(ctx, &MainnetParams{
    Validators:      21,
    InitialStake:    big.NewInt(2000),
    ConsensusParams: mainnetConsensus,
})

// Set up production monitoring
prod.EnableMonitoring(ctx, &MonitoringParams{
    MetricsEndpoint: "prometheus:9090",
    LogAggregation:  "elasticsearch:9200",
    AlertManager:    "alertmanager:9093",
})

// Enable automatic backups
prod.EnableBackups(ctx, &BackupParams{
    Interval: 6 * time.Hour,
    Storage:  "s3://lux-backups",
    Retention: 30 * 24 * time.Hour,
})
Migration from Other Platforms
// Migrate from Ethereum/Polygon/BSC
migrator := sdk.NewMigrator(luxSDK)

// Analyze existing deployment
analysis := migrator.Analyze(ctx, &MigrationSource{
    Type:     "ethereum",
    Endpoint: "https://mainnet.infura.io/v3/YOUR_KEY",
    Contracts: []string{
        "0x...", // Your contract addresses
    },
})

// Generate migration plan
plan := migrator.Plan(ctx, analysis, &MigrationTarget{
    Network: "lux-mainnet",
    VMType:  "evm",
    OptimizeFor: []string{"lower-fees", "faster-finality"},
})

// Execute migration
result := migrator.Execute(ctx, plan)
log.Printf("Migration complete: %d contracts, %d users migrated",
    result.ContractsMigrated, result.UsersMigrated)

πŸ”¬ Advanced Features

Custom Consensus Parameters
// Fine-tune consensus for your use case
consensus := &ConsensusParams{
    SnowballParameters: SnowballParameters{
        K:               21,  // Sample size
        AlphaPreference: 15,  // Quorum size
        AlphaConfidence: 19,  // Confidence threshold
        Beta:            8,   // Decision rounds
    },
    OptimalProcessing: 9630 * time.Millisecond,
}

network, err := luxSDK.LaunchNetworkWithConsensus(ctx, consensus)
Hardware Security Module (HSM) Integration
// Use HSM for validator keys
hsm := sdk.NewHSMIntegration(luxSDK, &HSMConfig{
    Provider: "thales",
    Endpoint: "hsm.internal:9999",
})

// Generate validator keys in HSM
validatorKey, err := hsm.GenerateValidatorKey(ctx, "validator-01")

// Sign transactions with HSM
signedTx, err := hsm.SignTransaction(ctx, tx, validatorKey)
Performance Optimization
// Configure for maximum throughput
perf := sdk.NewPerformanceOptimizer(luxSDK)

// Optimize for specific workload
perf.Optimize(ctx, &WorkloadProfile{
    TransactionType: "simple-transfer",
    ExpectedTPS:     50000,
    LatencyTarget:   100 * time.Millisecond,
})

// Enable performance monitoring
metrics := perf.StartMetrics(ctx)
go func() {
    for m := range metrics {
        log.Printf("TPS: %d, Latency: %v", m.TPS, m.Latency)
    }
}()

Requirements

  • Go 1.22 or higher
  • Access to a Lux node endpoint (optional)
  • For local development: Docker (optional, for netrunner)
  • For production: Linux/macOS/Windows

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

This SDK is licensed under the BSD 3-Clause License.

Support

πŸ—ΊοΈ Roadmap

Near Term (Q1 2025)
  • βœ… Full netrunner integration for network orchestration
  • βœ… CLI wrapper for all operations
  • βœ… Direct node API access
  • Enhanced WASM support (Rust, C++, AssemblyScript)
  • Advanced DeFi protocol templates
  • GraphQL API support
  • SDK plugins system
Medium Term (Q2-Q3 2025)
  • AI-powered network optimization
  • Zero-knowledge proof integration
  • Multi-cloud deployment automation
  • Advanced cross-chain messaging protocol
  • Built-in DEX and AMM templates
  • Mobile SDK (iOS/Android)
  • Browser SDK (WASM-based)
Long Term (Q4 2025+)
  • Quantum-resistant cryptography throughout
  • Fully autonomous network management
  • Inter-blockchain communication (IBC) support
  • Native integration with major cloud providers
  • Enterprise blockchain-as-a-service templates
  • Advanced governance modules
  • Regulatory compliance automation

πŸ’‘ Why Choose Lux SDK?

  1. Unified Interface: One SDK for all blockchain operations
  2. Production Ready: Battle-tested components from mainnet
  3. Developer Friendly: Intuitive APIs with excellent documentation
  4. Performance: Optimized for high-throughput applications
  5. Flexibility: Support for any VM type and consensus configuration
  6. Enterprise Grade: Built for mission-critical deployments
  7. Future Proof: Quantum-resistant and continuously evolving

Documentation ΒΆ

Overview ΒΆ

Package sdk provides extensions to the Lux SDK for building various VMs This extends the existing Lux SDK at ~/work/lux/sdk

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type AIExtension ΒΆ added in v1.3.0

type AIExtension struct {
	ModelRegistry   *ModelRegistry
	InferenceEngine *InferenceEngine
	AttestationGen  *AttestationGenerator
	ProofVerifier   *ProofVerifier
	TrainingManager *TrainingManager
}

func (*AIExtension) Initialize ΒΆ added in v1.3.0

func (e *AIExtension) Initialize(builder *VMBuilder) error

func (*AIExtension) Name ΒΆ added in v1.3.0

func (e *AIExtension) Name() string

func (*AIExtension) Start ΒΆ added in v1.3.0

func (e *AIExtension) Start(ctx context.Context) error

func (*AIExtension) Stop ΒΆ added in v1.3.0

func (e *AIExtension) Stop() error

type AIModel ΒΆ added in v1.3.0

type AIModel struct {
	ID           string
	Hash         []byte
	Provider     string
	Architecture string // transformer, cnn, rnn, etc
	Parameters   int64  // Number of parameters
	Attestation  []byte // Cryptographic attestation
	Performance  *ModelPerformance
}

type AttestationGenerator ΒΆ added in v1.3.0

type AttestationGenerator struct{}

func NewAttestationGenerator ΒΆ added in v1.3.0

func NewAttestationGenerator() *AttestationGenerator

type BFTConfig ΒΆ added in v1.3.0

type BFTConfig struct {
	// Deployment type
	DeploymentType DeploymentType

	// Network configuration
	NetworkID uint32
	ChainID   ids.ID
	NodeID    ids.NodeID

	// Consensus parameters
	MaxProposalWait    time.Duration
	MaxRebroadcastWait time.Duration

	// Quantum-safe mode (for Quasar Protocol)
	QuantumSafeMode bool

	// BLS signature aggregation
	BLSAggregation bool

	// Epoch configuration
	EpochNumber uint64
	StartTime   time.Time

	// Validator configuration
	Validators []ids.NodeID

	// Storage
	DB  database.Database
	WAL bft.WriteAheadLog

	// Logging
	Logger log.Logger

	// Enable replication protocol
	ReplicationEnabled bool
}

BFTConfig contains configuration for BFT consensus engine

type BFTConsensusEngine ΒΆ added in v1.3.0

type BFTConsensusEngine struct {
	// contains filtered or unexported fields
}

BFTConsensusEngine implements ConsensusEngine interface using the BFT package

func NewBFTConsensusEngine ΒΆ added in v1.3.0

func NewBFTConsensusEngine(config *BFTConfig) (*BFTConsensusEngine, error)

NewBFTConsensusEngine creates a new BFT consensus engine

func (*BFTConsensusEngine) AdvanceTime ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) AdvanceTime(duration time.Duration)

AdvanceTime hints to the engine that time has passed

func (*BFTConsensusEngine) Config ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) Config() *BFTConfig

Config returns the engine's configuration

func (*BFTConsensusEngine) Epoch ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) Epoch() *bft.Epoch

Epoch returns the underlying BFT epoch (for advanced use cases)

func (*BFTConsensusEngine) GetID ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) GetID() ids.ID

GetID returns the chain ID

func (*BFTConsensusEngine) GetMetadata ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) GetMetadata() *bft.ProtocolMetadata

GetMetadata returns the current consensus metadata

func (*BFTConsensusEngine) HandleMessage ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) HandleMessage(msg *bft.Message, from ids.NodeID) error

HandleMessage handles incoming consensus messages

func (*BFTConsensusEngine) Initialize ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) Initialize(
	blockBuilder bft.BlockBuilder,
	storage bft.Storage,
	signer bft.Signer,
	verifier bft.SignatureVerifier,
	aggregator bft.SignatureAggregator,
	communication bft.Communication,
	qcDeserializer bft.QCDeserializer,
	blockDeserializer bft.BlockDeserializer,
) error

Initialize initializes the BFT epoch with the provided components

func (*BFTConsensusEngine) IsRunning ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) IsRunning() bool

IsRunning returns whether the engine is running

func (*BFTConsensusEngine) SetBLSAggregation ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) SetBLSAggregation(enabled bool)

SetBLSAggregation enables or disables BLS signature aggregation

func (*BFTConsensusEngine) SetQuantumMode ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) SetQuantumMode(enabled bool)

SetQuantumMode enables or disables quantum-safe mode

func (*BFTConsensusEngine) SetVerkleWitnesses ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) SetVerkleWitnesses(enabled bool)

SetVerkleWitnesses enables or disables Verkle tree witnesses

func (*BFTConsensusEngine) Start ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) Start(ctx context.Context) error

Start starts the BFT consensus engine

func (*BFTConsensusEngine) Stop ΒΆ added in v1.3.0

func (e *BFTConsensusEngine) Stop() error

Stop stops the BFT consensus engine

type BlockchainParams ΒΆ

type BlockchainParams struct {
	Name    string
	Type    blockchain.BlockchainType
	VMType  blockchain.VMType
	ChainID *big.Int
	Genesis []byte
	Network *network.Network
}

BlockchainParams defines parameters for creating and deploying a blockchain

type Clearinghouse ΒΆ added in v1.3.0

type Clearinghouse struct{}

func NewClearinghouse ΒΆ added in v1.3.0

func NewClearinghouse() *Clearinghouse

Factory functions for extensions

type ConsensusEngine ΒΆ added in v1.3.0

type ConsensusEngine interface {
	Engine
	SetQuantumMode(enabled bool)
	SetBLSAggregation(enabled bool)
	SetVerkleWitnesses(enabled bool)
}

ConsensusEngine interface (extends existing)

type Context ΒΆ added in v1.3.0

type Context struct {
	NetworkID uint32
	SubnetID  ids.ID
	ChainID   ids.ID
	NodeID    ids.NodeID
}

Context represents VM context

type CrossChainBridge ΒΆ added in v1.3.0

type CrossChainBridge struct{}

func NewCrossChainBridge ΒΆ added in v1.3.0

func NewCrossChainBridge() *CrossChainBridge

type DEXExtension ΒΆ added in v1.3.0

type DEXExtension struct {
	OrderBooks    map[string]*OrderBook
	Clearinghouse *Clearinghouse
	FundingEngine *FundingEngine
	Bridge        *CrossChainBridge
	Vaults        *VaultManager
	StakingPools  *StakingManager
	Multisig      *MultisigManager
}

func (*DEXExtension) Initialize ΒΆ added in v1.3.0

func (e *DEXExtension) Initialize(builder *VMBuilder) error

func (*DEXExtension) Name ΒΆ added in v1.3.0

func (e *DEXExtension) Name() string

func (*DEXExtension) Start ΒΆ added in v1.3.0

func (e *DEXExtension) Start(ctx context.Context) error

func (*DEXExtension) Stop ΒΆ added in v1.3.0

func (e *DEXExtension) Stop() error

type DeploymentType ΒΆ added in v1.3.0

type DeploymentType int

DeploymentType indicates where the BFT consensus is deployed

const (
	// MainnetDeployment is for Lux mainnet
	MainnetDeployment DeploymentType = iota

	// TestnetDeployment is for Lux testnet
	TestnetDeployment

	// SovereignL1Deployment is for sovereign quantum-safe L1 chains
	// secured by Quasar Protocol (Lux Quantum Consensus)
	SovereignL1Deployment
)

func (DeploymentType) String ΒΆ added in v1.3.0

func (dt DeploymentType) String() string

type EncryptedValue ΒΆ added in v1.3.0

type EncryptedValue struct {
	Ciphertext []byte
	Level      int // Noise level
	Metadata   map[string]interface{}
}

type Engine ΒΆ added in v1.3.0

type Engine interface {
	GetID() ids.ID
}

Engine interface for consensus

type FHEExtension ΒΆ added in v1.3.0

type FHEExtension struct {
	Scheme         FHEScheme
	KeyManager     *FHEKeyManager
	EncryptedState map[string]*EncryptedValue
	Computer       *HomomorphicComputer
}

func (*FHEExtension) Initialize ΒΆ added in v1.3.0

func (e *FHEExtension) Initialize(builder *VMBuilder) error

func (*FHEExtension) Name ΒΆ added in v1.3.0

func (e *FHEExtension) Name() string

func (*FHEExtension) Start ΒΆ added in v1.3.0

func (e *FHEExtension) Start(ctx context.Context) error

func (*FHEExtension) Stop ΒΆ added in v1.3.0

func (e *FHEExtension) Stop() error

type FHEKeyManager ΒΆ added in v1.3.0

type FHEKeyManager struct {
	PublicKey     []byte
	EvaluationKey []byte
	RelinKey      []byte
	GaloisKeys    map[int][]byte
}

func NewFHEKeyManager ΒΆ added in v1.3.0

func NewFHEKeyManager() *FHEKeyManager

type FHEScheme ΒΆ added in v1.3.0

type FHEScheme string
const (
	SchemeCKKS FHEScheme = "ckks" // For approximate arithmetic
	SchemeBFV  FHEScheme = "bfv"  // For exact arithmetic
	SchemeTFHE FHEScheme = "tfhe" // For boolean circuits
)

type FeatureSet ΒΆ added in v1.3.0

type FeatureSet struct {
	// Consensus features
	QuantumResistant bool // Ringtail lattice-based
	BLSAggregation   bool // BLS signature aggregation
	VerkleWitnesses  bool // Verkle tree witnesses
	FPC              bool // Fast Probabilistic Consensus

	// Cryptographic features
	FHE         bool // Fully Homomorphic Encryption
	MPC         bool // Multi-Party Computation
	ZKProofs    bool // Zero-Knowledge Proofs
	PostQuantum bool // Post-quantum cryptography

	// Execution features
	GPU  bool // GPU acceleration
	FPGA bool // FPGA acceleration
	DPDK bool // Kernel bypass networking
	RDMA bool // Remote Direct Memory Access

	// Application features
	DEX     bool // Decentralized exchange
	AI      bool // AI/ML capabilities
	Oracle  bool // Oracle functionality
	Privacy bool // Privacy features
	Storage bool // Decentralized storage
}

FeatureSet defines features a VM can enable

type FundingEngine ΒΆ added in v1.3.0

type FundingEngine struct{}

func NewFundingEngine ΒΆ added in v1.3.0

func NewFundingEngine() *FundingEngine

type HomomorphicComputer ΒΆ added in v1.3.0

type HomomorphicComputer struct {
	// contains filtered or unexported fields
}

func (*HomomorphicComputer) Add ΒΆ added in v1.3.0

func (*HomomorphicComputer) Multiply ΒΆ added in v1.3.0

type InferenceEngine ΒΆ added in v1.3.0

type InferenceEngine struct {
	// contains filtered or unexported fields
}

func NewInferenceEngine ΒΆ added in v1.3.0

func NewInferenceEngine() *InferenceEngine

func (*InferenceEngine) EnableGPU ΒΆ added in v1.3.0

func (e *InferenceEngine) EnableGPU()

type LatticeCrypto ΒΆ added in v1.3.0

type LatticeCrypto struct {
	Dimension         int
	Modulus           *big.Int
	StandardDeviation float64
	SecurityLevel     int // 128, 192, or 256 bits
}

type LuxSDK ΒΆ

type LuxSDK struct {
	// contains filtered or unexported fields
}

LuxSDK is the main SDK interface providing comprehensive blockchain development capabilities

func New ΒΆ

func New(cfg *config.Config) (*LuxSDK, error)

New creates a new instance of the Lux SDK

func (*LuxSDK) Blockchains ΒΆ

func (sdk *LuxSDK) Blockchains() *blockchain.Builder

Blockchains returns the blockchain builder for blockchain operations

func (*LuxSDK) CreateAndDeployBlockchain ΒΆ

func (sdk *LuxSDK) CreateAndDeployBlockchain(ctx context.Context, params *BlockchainParams) (*blockchain.Blockchain, error)

CreateAndDeployBlockchain creates and deploys a blockchain

func (*LuxSDK) LaunchNetwork ΒΆ

func (sdk *LuxSDK) LaunchNetwork(ctx context.Context, networkType string, numNodes int) (*network.Network, error)

LaunchNetwork launches a network using the network manager

func (*LuxSDK) Networks ΒΆ

func (sdk *LuxSDK) Networks() *network.NetworkManager

Networks returns the network manager for network operations

type MPCComputer ΒΆ added in v1.3.0

type MPCComputer struct {
	// contains filtered or unexported fields
}

type MPCExtension ΒΆ added in v1.3.0

type MPCExtension struct {
	Protocol     MPCProtocol
	Parties      map[string]*Party
	SecretShares map[string][]*SecretShare
	Computer     *MPCComputer
}

func (*MPCExtension) Initialize ΒΆ added in v1.3.0

func (e *MPCExtension) Initialize(builder *VMBuilder) error

func (*MPCExtension) Name ΒΆ added in v1.3.0

func (e *MPCExtension) Name() string

func (*MPCExtension) Start ΒΆ added in v1.3.0

func (e *MPCExtension) Start(ctx context.Context) error

func (*MPCExtension) Stop ΒΆ added in v1.3.0

func (e *MPCExtension) Stop() error

type MPCProtocol ΒΆ added in v1.3.0

type MPCProtocol string
const (
	ProtocolGMW  MPCProtocol = "gmw"  // Goldreich-Micali-Wigderson
	ProtocolBGW  MPCProtocol = "bgw"  // Ben-Or-Goldwasser-Wigderson
	ProtocolSPDZ MPCProtocol = "spdz" // Fast MPC with preprocessing
	ProtocolABY  MPCProtocol = "aby"  // Mixed protocol
)

type ModelPerformance ΒΆ added in v1.3.0

type ModelPerformance struct {
	Accuracy   float64
	Latency    time.Duration
	Throughput float64
}

type ModelRegistry ΒΆ added in v1.3.0

type ModelRegistry struct {
	Models map[string]*AIModel
	// contains filtered or unexported fields
}

type MultisigManager ΒΆ added in v1.3.0

type MultisigManager struct{}

func NewMultisigManager ΒΆ added in v1.3.0

func NewMultisigManager() *MultisigManager

type NetworkManager ΒΆ added in v1.3.0

type NetworkManager interface {
	Send(msg []byte, nodeID ids.NodeID) error
	Broadcast(msg []byte) error
	EnableDPDK() error
	EnableRDMA() error
}

NetworkManager interface (extends existing)

type NodeInfo ΒΆ

type NodeInfo struct {
	NodeID      string
	Version     string
	NetworkID   uint32
	NetworkName string
}

NodeInfo contains information about a node

type OrderBook ΒΆ added in v1.3.0

type OrderBook struct{}

Stub types for extensions

type Party ΒΆ added in v1.3.0

type Party struct {
	ID        string
	PublicKey *ecdsa.PublicKey
	Shares    map[string]*SecretShare
}

type ProofVerifier ΒΆ added in v1.3.0

type ProofVerifier struct{}

func NewProofVerifier ΒΆ added in v1.3.0

func NewProofVerifier() *ProofVerifier

type QuantumCertificate ΒΆ added in v1.3.0

type QuantumCertificate struct {
	BlockID       ids.ID
	Round         int
	LatticeProof  []byte
	BLSSignature  []byte
	VerkleWitness []byte
}

type QuantumExtension ΒΆ added in v1.3.0

type QuantumExtension struct {
	Lattice       *LatticeCrypto
	Ringtail      *RingtailConsensus
	QuantumProofs *QuantumProofSystem
}

func (*QuantumExtension) Initialize ΒΆ added in v1.3.0

func (e *QuantumExtension) Initialize(builder *VMBuilder) error

func (*QuantumExtension) Name ΒΆ added in v1.3.0

func (e *QuantumExtension) Name() string

func (*QuantumExtension) Start ΒΆ added in v1.3.0

func (e *QuantumExtension) Start(ctx context.Context) error

func (*QuantumExtension) Stop ΒΆ added in v1.3.0

func (e *QuantumExtension) Stop() error

type QuantumProofSystem ΒΆ added in v1.3.0

type QuantumProofSystem struct {
	ProofType string // lattice, code-based, hash-based, multivariate
}

type RingtailConsensus ΒΆ added in v1.3.0

type RingtailConsensus struct {
	Rounds       int // 2-round consensus
	Threshold    float64
	Certificates map[ids.ID]*QuantumCertificate
}

type SecretShare ΒΆ added in v1.3.0

type SecretShare struct {
	ShareID   string
	PartyID   string
	Value     []byte
	Threshold int
}

type StakingManager ΒΆ added in v1.3.0

type StakingManager struct{}

func NewStakingManager ΒΆ added in v1.3.0

func NewStakingManager() *StakingManager

type StateDB ΒΆ added in v1.3.0

type StateDB interface {
	Get(key []byte) ([]byte, error)
	Put(key []byte, value []byte) error
	Delete(key []byte) error
	RegisterHandler(prefix string, handler StateHandler) error
}

StateDB interface for state management (extends existing)

type StateHandler ΒΆ added in v1.3.0

type StateHandler func(key, value []byte) error

type TrainingManager ΒΆ added in v1.3.0

type TrainingManager struct{}

func NewTrainingManager ΒΆ added in v1.3.0

func NewTrainingManager() *TrainingManager

type VMBuilder ΒΆ added in v1.3.0

type VMBuilder struct {
	// Core SDK components (existing)
	Context   *Context
	DB        database.Database
	State     StateDB
	Consensus ConsensusEngine
	Network   NetworkManager

	// Extended components for various VMs
	Extensions map[string]VMExtension
	Features   *FeatureSet
	// contains filtered or unexported fields
}

VMBuilder provides a unified interface for building VMs on Lux This extends the existing SDK with additional capabilities needed for: DEXVM, AIVM, FHEVM, MPCVM, QuantumVM, and more

func NewVMBuilder ΒΆ added in v1.3.0

func NewVMBuilder(ctx *Context, db database.Database) *VMBuilder

NewVMBuilder creates a new VM builder

func (*VMBuilder) Build ΒΆ added in v1.3.0

func (b *VMBuilder) Build() error

Build builds the VM with all extensions

func (*VMBuilder) Start ΒΆ added in v1.3.0

func (b *VMBuilder) Start() error

Start starts the VM

func (*VMBuilder) Stop ΒΆ added in v1.3.0

func (b *VMBuilder) Stop() error

Stop stops the VM

func (*VMBuilder) WithExtension ΒΆ added in v1.3.0

func (b *VMBuilder) WithExtension(ext VMExtension) *VMBuilder

WithExtension adds an extension to the VM

func (*VMBuilder) WithFeatures ΒΆ added in v1.3.0

func (b *VMBuilder) WithFeatures(features *FeatureSet) *VMBuilder

WithFeatures enables features

type VMExtension ΒΆ added in v1.3.0

type VMExtension interface {
	Name() string
	Initialize(builder *VMBuilder) error
	Start(ctx context.Context) error
	Stop() error
}

VMExtension represents VM-specific functionality

type VaultManager ΒΆ added in v1.3.0

type VaultManager struct{}

func NewVaultManager ΒΆ added in v1.3.0

func NewVaultManager() *VaultManager

Directories ΒΆ

Path Synopsis
Package crypto provides functionality for interacting with Ed25519 public and private keys.
Package crypto provides functionality for interacting with Ed25519 public and private keys.
internal
evm
Package keys provides key derivation and management utilities for LUX.
Package keys provides key derivation and management utilities for LUX.
mocks
ethclient
Package mock_ethclient is a generated GoMock package.
Package mock_ethclient is a generated GoMock package.
Package netrunner provides integration with the Lux netrunner tool for managing test networks and blockchain deployments.
Package netrunner provides integration with the Lux netrunner tool for managing test networks and blockchain deployments.
tools
xfer command
xfer is a simple tool to transfer LUX from X-Chain to P-Chain Usage: xfer -uri http://127.0.0.1:9630 -key ~/.lux/keys/mainnet-deployer.pk -amount 1000000000 Or set LUX_PRIVATE_KEY env var (hex format) or LUX_MNEMONIC env var (24 words)
xfer is a simple tool to transfer LUX from X-Chain to P-Chain Usage: xfer -uri http://127.0.0.1:9630 -key ~/.lux/keys/mainnet-deployer.pk -amount 1000000000 Or set LUX_PRIVATE_KEY env var (hex format) or LUX_MNEMONIC env var (24 words)
txs
// Copyright (C) 2025, Lux Partners Limited All rights reserved See the file LICENSE for licensing terms.
// Copyright (C) 2025, Lux Partners Limited All rights reserved See the file LICENSE for licensing terms.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL