rust-pact
A Rust library for interacting with Kadena Pact smart contracts and blockchain operations.
Features
- Key pair generation and management
- Pact command construction (exec, cont)
- Cross-chain transfer operations
- SPV proof retrieval
- Trans### ✅ Successfully Resolved Issues
- Timeout Issue: Fixed HTTP request timeouts by using poll-before-listen approach
- PactId Extraction: Corrected pactId extraction from listen response
- Transaction Mining: Successfully polls until transaction is mined
- SPV Proof Retrieval: Implements proper SPV polling with configurable attempts
⚠️ Known Limitations
- SPV Proof Timing: On testnet, SPV proofs may take 10+ minutes to become available after cross-chain initiation
- Expected Behavior: The process will show "obtaining SPV proof..." and may take several minutes
- Network Timeouts: Testnet can be slow; use mainnet for faster operations
- Interrupt Handling: You can interrupt with Ctrl+C during SPV polling if neededng and status checking
- Unified cross-chain transfer workflow
Example Usage
use crypto;
use KeyPair;
use api;
use lang;
use simple;
use fetch;
For more examples, see the examples/ directory.
Tools Usage Example
use ;
use KeyPair;
// Run with: cargo run --example tools
// To perform real network calls set env var RUN_LIVE=1 (these hit public Chainweb endpoints)
Cross-Chain Transfer Example
use ;
use KeyPair;
use json;
Unified Cross-Chain Transfer
For a simplified, single-call cross-chain transfer that handles all the polling and SPV proof retrieval automatically:
use ;
use KeyPair;
Configuration Options
The CrossChainConfig struct allows tuning of polling behavior:
attempts_tx: Max attempts for initial transaction polling (default: 30, 0 = infinite)interval_tx_ms: Interval between tx polls in ms (default: 5000)post_confirm_wait_ms: Delay after tx success before SPV fetch (default: 10000)attempts_spv: Max attempts for SPV proof polling (default: 0 = infinite, >0 = use limit)interval_spv_ms: Interval between SPV polls in ms (default: 5000)attempts_final: Max attempts for final completion polling (default: 30, 0 = infinite)interval_final_ms: Interval between final polls in ms (default: 5000)verbose: Enable diagnostic logging (default: false)max_total_time_ms: Max total time for all polling combined (default: 360000ms = 6min, 0 = no limit)
All values can be overridden via environment variables prefixed with XCHAIN_, e.g., XCHAIN_ATTEMPTS=0 for infinite polling.
Note: SPV proof polling defaults to infinite attempts since SPV proofs can take significant time to become available after cross-chain transactions.
Sample Output
Run the example: cargo run --example crosschain_full
Current Status & Known Limitations
✅ Implemented Features
- Basic Pact command construction and signing
- Cross-chain transfer initiation and completion
- Unified cross-chain transfer workflow (
crosschain_transfer_full) - Configurable polling with environment variables
- Transaction status polling and SPV proof retrieval
- Support for both testnet and mainnet
⚠️ Known Limitations
- SPV Proof Timing: On testnet, SPV proofs may take 2-5 minutes to become available after cross-chain initiation (now handled with infinite polling by default)
- Timeout Behavior: Default 6-minute timeout may not be sufficient for slow networks - increase
XCHAIN_MAX_TOTAL_TIME_MSfor testnet - Network Dependencies: Requires active Kadena network connectivity for live operations
- Expected Behavior: Final completion timeout after SPV retrieval is normal testnet behavior
🔧 Configuration Options
Configure cross-chain behavior via environment variables:
# Polling attempts (0 = infinite)
# Transaction polling attempts
# SPV polling attempts (0 = infinite - DEFAULT)
# Final completion polling attempts
# Timing (milliseconds)
# Transaction poll interval
# SPV poll interval
# Wait after tx confirmation
# Total timeout (6 minutes)
# Other options
# Enable verbose logging
# Enable live network calls
🧪 Testing
For testing cross-chain operations:
- Use testnet (
testnet04) for development - Fund test accounts with KDA tokens
- Expect SPV proofs to take several minutes
- Use
XCHAIN_SPV_ATTEMPTS=0for infinite SPV polling
Build & Run
Verbose mode and troubleshooting
Enable verbose logs and adjust timing via environment variables:
# Enable live network calls (testnet/mainnet based on your params)
# Verbose logging
# Polling attempts (0 = infinite)
# Intervals & timeouts (ms)
# 20 minutes recommended for testnet
# Run the example
Tips:
- ✅ Timeout Issue Resolved: No more HTTP request timeouts - implementation uses poll-before-listen approach
- ✅ SPV Polling Now Infinite:
XCHAIN_SPV_ATTEMPTS=0by default for unlimited SPV attempts - ✅ Expected Testnet Behavior: SPV proofs take 2-5 minutes; final completion timeout is normal
- SPV proofs can take several minutes on testnet; set long total timeout and infinite SPV attempts.
- We fetch SPV from the source chain and pass the targetChainId.
- Final confirmation uses listen on the target chain; some nodes may return an error message like "resumePact: pact completed" which is treated as successful completion.
- On macOS, you may need to accept Xcode license to run examples: