dart_wallet_adapter 0.0.51 copy "dart_wallet_adapter: ^0.0.51" to clipboard
dart_wallet_adapter: ^0.0.51 copied to clipboard

Platformweb

A wrapper around the JS Wallet Adapter library for Dart

Dart Wallet Adapter #

Dart version License: MIT

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 #

  • 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

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';

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:

  1. 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();
  1. Connect to the wallet: Connecting to the wallet is as simple as calling the connect method on the adapter instance.
await walletAdapter.connect();
  1. 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);
  1. 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();

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);

Development #

This library is still under active development. More features and improvements are coming.

Contributing #

dart commit.dart -m "Some message" --release

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.

0
likes
90
pub points
65%
popularity

Publisher

unverified uploader

A wrapper around the JS Wallet Adapter library for Dart

Repository

Documentation

API reference

License

MIT (LICENSE)

Dependencies

dart_solana_adapter, flutter, js

More

Packages that depend on dart_wallet_adapter