0 purchases
dart wallet adapter
Dart Wallet Adapter #
Dart Wallet Adapter is a Dart wrapper library for the JavaScript Wallet Adapter library. The aim of this library is to facilitate interactions with cryptocurrency wallets, including those on the Solana network.
Table of Contents #
Features
Installation
Usage
Development
Contributing
License
Features #
Wraps the JavaScript Wallet Adapter library in Dart
Allows interaction with cryptocurrency wallets
Includes support for the Solana network
Installation #
To use this library in your project, add it to your pubspec.yaml file:
dependencies:
dart_wallet_adapter: ^0.0.38
copied to clipboard
Then, run flutter pub get to fetch the package.
Usage #
The Dart Wallet Adapter is a Dart package that provides easy integration with Solana wallets. To utilize its functionality, start by importing the library:
import 'package:dart_wallet_adapter/dart_wallet_adapter.dart';
copied to clipboard
Before any usage, the Dart Wallet Adapter library must be properly initialized. During initialization, the dart_wallet_adapter JavaScript library is also set up automatically, meaning that you don't need to perform this step separately.
Here's a general workflow with the library:
Create a wallet adapter instance: After initialization, you can create an instance of a wallet adapter for a specific wallet. This instance serves as your main point of interaction with the wallet.
final walletAdapter = PhantomWalletAdapter();
copied to clipboard
Connect to the wallet: Connecting to the wallet is as simple as calling the connect method on the adapter instance.
await walletAdapter.connect();
copied to clipboard
Handle wallet events: Dart Wallet Adapter offers a set of event handlers for specific wallet events such as 'connect', 'disconnect', and 'error'. These handlers are the main means of interaction with the wallet's state and actions. For example, to handle a wallet connection, you should use a predefined function or keep a reference to an anonymous function to allow unsubscribing later:
void handleConnect(publicKey) {
print('Wallet connected with public key: $publicKey');
}
setupWalletOnConnectEvent(walletAdapter, handleConnect);
copied to clipboard
Disconnect from the wallet: When you are done interacting with the wallet or wish to disconnect for any reason, you can do so by calling the disconnect method on the adapter instance.
await walletAdapter.disconnect();
copied to clipboard
Please note that it is important to handle any potential exceptions that may occur during the connection or disconnection process to ensure a smooth user experience.
In addition, the wallet's state may change due to user actions outside of your application (for example, if the user manually disconnects the wallet in their browser). Therefore, using the event handlers to listen for changes in the wallet's state is a crucial part of effectively managing the wallet connection in your application.
Remember to unsubscribe from the events when they are no longer needed to avoid potential memory leaks. To unsubscribe, you need to use the same function reference that was used to subscribe. Here's how you can do that:
removeWalletOnConnectEvent(walletAdapter, handleConnect);
copied to clipboard
Development #
This library is still under active development. More features and improvements are coming.
Contributing #
dart commit.dart -m "Some message" --release
copied to clipboard
Contributions are more than welcome!
Please read our contributing guide to learn about our development process,
how to propose bugfixes and improvements, and how to build and test your changes.
License #
This project is licensed under the MIT License - see the LICENSE file for details.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.