stxn-sdk
v0.1.10
Published
A TypeScript/JavaScript SDK for Smart Transaction Development on Lestnet. Build hybrid dApps with STXN protocol, enabling advanced transaction flows and programmable transaction management.
Maintainers
Readme
stxn-sdk
A TypeScript/JavaScript SDK for Smart Transaction Development on Lestnet. Build hybrid dApps with STXN protocol, enabling advanced transaction flows and programmable transaction management.
Features
- 🚀 Easy-to-use API for Lestnet blockchain interactions
- 💼 Comprehensive wallet management
- 💸 Transaction handling and utilities
- 🔄 Built-in retry mechanisms for network operations
- 📊 Unit conversion helpers
- 🔧 TypeScript support with full type definitions
Installation
npm install stxn-sdkQuick Start
import { lestnet, createRandom, sendTx, lethToWei } from 'stxn-sdk';
// Initialize provider
const provider = lestnet();
// Create a new wallet
const wallet = createRandom();
console.log('New wallet:', wallet.address);
// Send transaction
const tx = await sendTx({
to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
value: lethToWei('1.5'),
privateKey: wallet.privateKey
});
console.log('Transaction hash:', tx.hash);API Reference
Provider
import { lestnet } from 'stxn-sdk';
// Initialize provider
const provider = lestnet();
// Get network information
const network = await provider.getNetwork();
console.log('Chain ID:', network.chainId);
// Get account balance
const balance = await provider.getBalance('0x...');Wallet Operations
import { createRandom } from 'stxn-sdk';
// Create new wallet
const wallet = createRandom();
console.log({
address: wallet.address,
privateKey: wallet.privateKey,
mnemonic: wallet.mnemonic.phrase
});Transaction Management
import { sendTx, lethToWei } from 'stxn-sdk';
// Send LETH
const tx = await sendTx({
to: '0x...',
value: lethToWei('1.5'),
privateKey: '0x...'
});
// Wait for confirmation
const receipt = await tx.wait();Unit Conversions
import { lethToWei, weiToLeth, formatLeth } from 'stxn-sdk';
// Convert LETH to Wei
const wei = lethToWei('1.5');
// Convert Wei to LETH
const leth = weiToLeth('1500000000000000000');
// Format LETH amount with units
const formatted = formatLeth('1500000000000000000');
// Output: "1.5 LETH"Error Handling
The SDK includes built-in error handling and retry mechanisms for network operations:
import { sendTx } from 'stxn-sdk';
try {
const tx = await sendTx({
to: '0x...',
value: lethToWei('1.5'),
privateKey: '0x...'
});
} catch (error) {
if (error.code === 'INSUFFICIENT_FUNDS') {
console.error('Not enough LETH to send transaction');
} else if (error.code === 'NETWORK_ERROR') {
console.error('Network connection issue');
} else {
console.error('Unknown error:', error);
}
}CLI Tool
For command-line interactions with Lestnet, check out our dedicated CLI tool: stxn-cli.
Development
# Install dependencies
npm install
# Build the package
npm run build
# Run tests
npm test
# Run linter
npm run lintRequirements
- Node.js >= 16.0.0
- npm >= 7.0.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the ISC License - see the LICENSE file for details.
Related Projects
- stxn-cli - Command-line interface for Lestnet
- Lestnet Explorer - Block explorer for Lestnet
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.
