kalp_dlt 1.0.1

SDKflutter
Platformandroidiosmacos

A Flutter package for interacting with distributed ledger technology (DLT) through the Kalp wallet system.

Kalp DLT

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.

pub package License: MIT

Features

  • Wallet Management

    • Create seed phrases for new wallets
    • Register wallets with 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:

  1. Visit and Register at Kalp Studio Portal
  2. Generate your API key from the wallet creator app section
  3. Store your API key securely as it will be required for initialization

Add kalp_dlt to your pubspec.yaml file:

dependencies:
  kalp_dlt: ^1.0.0

Then run:

flutter pub get

Getting Started

To use this package, you need to initialize it with your configuration:

import 'package:kalp_dlt/kalp_dlt.dart';

void main() {
  // Initialize the Kalp DLT with your configuration
  final kalpDlt = KalpDLT.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

Test Network

  • URL: https://ngl-userreg-test.kalp.network/v1/pki/
  • Channel Name: prod-test-mainnet

Main Network

  • URL: https://ngl-mumbai-userreg.kalp.network/v1/pki/
  • Channel Name: kalpchaintwo

Gateway Configuration

Test Network

  • URL: https://rpc-mumbai-test.kalp.network/transaction/v1/
  • Network Name: kalptantra

Main Network

  • URL: https://rpc-mumbai.kalp.network/transaction/v1/
  • Network Name: kalptwo

Usage Example with Network Configuration

// For Test Network
final kalpDlt = KalpDLT.initialize(
  nglBaseUrl: 'https://ngl-userreg-test.kalp.network/v1/pki/',
  gatewayBaseUrl: 'https://rpc-mumbai-test.kalp.network/transaction/v1/',
  apiKey: 'your-api-key',
);

// For Main Network
final kalpDlt = KalpDLT.initialize(
  nglBaseUrl: 'https://ngl-mumbai-userreg.kalp.network/v1/pki/',
  gatewayBaseUrl: 'https://rpc-mumbai.kalp.network/transaction/v1/',
  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');
  },
);

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:

  1. Clone the repository
  2. Navigate to the example directory
  3. Run flutter pub get
  4. 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.