Kalp DLT Wallet
A Flutter package for interacting with distributed ledger technology (DLT) through the Kalp wallet system. This package provides a simple interface for creating and managing wallets, as well as performing blockchain operations.
Features
-
Wallet Management
- Create seed phrases for new wallets
- Register wallets on Kalp DLT blockchain
- Import existing wallets on Kalp DLT blockchain
-
Blockchain Operations
- Read data from the blockchain
- Write data to the blockchain
- Calculate gas fees for transactions
Installation
Before using this package, you'll need to generate an API key:
- Visit https://accounts.kalp.studio/login create or login with your credentials
- Select Kalp DLT Developer Portal and click on Go To Portal
- Select KS Wallet and click on explore
- On left hand side click on Open API
- Now Click On Create API Auth key
- Provide Key name and description (optional)
- Now Copy API Auth Key and use it inside Kalp-DLT-Wallet-SDK
Add kalp_dlt_wallet
to your pubspec.yaml
file:
dependencies:
kalp_dlt_wallet: ^1.0.2
Then run:
flutter pub get
Getting Started
To use this package, you need to initialize it with your configuration:
import 'package:kalp_dlt_wallet/kalp_dlt_wallet.dart';
void main() {
// Initialize the Kalp DLT with your configuration
final kalpDlt = KalpDLTWallet.initialize(
nglBaseUrl: 'https://your-ngl-service.com',
gatewayBaseUrl: 'https://your-gateway-service.com',
apiKey: 'your-api-key', // Add your API key here
);
// Now you can use kalpDlt to interact with the blockchain
}
Network Configuration
The package supports both test and main networks. Here are the configuration details:
NGL Configuration
Network
- URL:
https://************.network/v1/pki/
- Channel Name:
**********
Gateway Configuration
Network
- URL:
https://rpc-********.network/transaction/v1/
- Network Name:
**********
Usage Example with Network Configuration
// For Test Network
final kalpDlt = KalpDLTWallet.initialize(
nglBaseUrl: 'Your NGL base URL for test network',
gatewayBaseUrl: 'Your Gateway base URL for test network'
apiKey: 'your-api-key',
);
Usage
Creating a Wallet
// Generate seed words
final seedWords = await kalpDlt.createSeedWords();
print('Generated seed words: $seedWords');
// Create a wallet with the generated seed words
await kalpDlt.createWalletWithSeedWords(
seedWords: seedWords.split(' '),
channelName: 'your-channel-name',
callback: (wallet) {
// Handle the created wallet
print('Wallet created with enrollment ID: ${wallet.enrollmentId}');
},
errorCallback: (error) {
// Handle any errors
print('Error creating wallet: $error');
},
);
Importing an Existing Wallet
// Import a wallet using existing seed words
final existingSeedWords = 'word1 word2 word3 ... word12';
await kalpDlt.createWalletWithSeedWords(
seedWords: existingSeedWords.split(' '),
channelName: 'your-channel-name',
importWallet: true,
callback: (wallet) {
// Handle the imported wallet
print('Wallet imported with enrollment ID: ${wallet.enrollmentId}');
},
errorCallback: (error) {
// Handle any errors
print('Error importing wallet: $error');
},
);
Using Private Key
// Validate private key before importing
if (KalpDLTWallet.isValidPrivateKey(privateKey)) {
await kalpDlt.importWalletWithPrivateKey(
channelName: 'your-channel-name',
privateKey: privateKey,
callback: (wallet) {
// Handle the imported wallet
print('Wallet imported with enrollment ID: ${wallet.enrollmentId}');
},
errorCallback: (error) {
// Handle any errors
print('Error importing wallet: $error');
},
);
} else {
print('Invalid private key format');
}
Reading from the Blockchain
// Create a proposal for reading data
final proposal = Proposal(
walletAddress: 'your-enrollment-id',
network: 'gateway-network-name',
contractAddress: 'gateway-contract-address',
functionName: 'your-function-name',
functionParams:<String>[],
publicCertificate: 'your-public-certificate',
);
// Read data from the blockchain
final result = await kalpDlt.read(
proposal: proposal,
);
print('Read result: $result');
Writing to the Blockchain
// Create a proposal for writing data
final proposal = Proposal(
walletAddress: 'your-enrollment-id',
network: 'gateway-network-name',
contractAddress: 'gateway-contract-address',
functionName: 'your-function-name',
functionParams:<String>[],
publicCertificate: 'your-public-certificate',
);
// Write data to the blockchain
final result = await kalpDlt.write(
proposal: proposal,
);
print('Write result: $result');
Calculating Gas Fees
// Create a proposal for a transaction
final proposal = Proposal(
walletAddress: 'your-enrollment-id',
network: 'gateway-network-name',
contractAddress: 'gateway-contract-address',
functionName: 'your-function-name',
functionParams:<String>[],
publicCertificate: 'your-public-certificate',
);
// Calculate gas fees for the transaction
final fees = await kalpDlt.gasFees(
proposal: proposal,
);
print('Gas fees: $fees');
Error Handling
The package provides comprehensive error handling:
try {
await kalpDlt.createWalletWithSeedWords(
seedWords: seedWords.split(' '),
channelName: 'your-channel-name',
callback: (wallet) {
// Success
},
errorCallback: (error) {
// This will be called for specific wallet creation errors
print('Wallet creation error: $error');
},
);
} catch (e) {
// This will catch any other exceptions
print('Unexpected error: $e');
}
Example
A complete example application is available in the /example
folder of this package. To run the example:
- Clone the repository
- Navigate to the example directory
- Run
flutter pub get
- Run
flutter run
📜 Requirements
- Flutter: >=3.0.0
- Dart: >=2.17.0
🔗Security Considerations
- The seed phrases generated by this package are sensitive information and should be handled securely.
- Always use HTTPS URLs for your services to ensure secure communication.
- Consider implementing additional security measures such as biometric authentication before performing sensitive operations.
Reporting any bug
- Raise a ticket on KALP Studio Portal.
License
This package is available under the MIT License. See the LICENSE file for more information.