web3_universal_dapp 0.1.1+1
web3_universal_dapp: ^0.1.1+1 copied to clipboard
dApp provider and EIP-1193 ecosystem support for Web3 Universal SDK. Facilitates wallet connection and interaction.
dart_web3_dapp #
A comprehensive application framework for building decentralized applications in Dart and Flutter. It provides the glue that connects your UI to state management, session persistence, and multi-provider connectivity.
π Features #
- Unified Provider Store: Switch between Injected, Reown, and Ledger providers without rewriting UI logic.
- Reactive State: Stream-based updates for account changes, network swaps, and connection status.
- Auto-Discovery (EIP-6963): Intelligent detection of installed browser wallets on Web platforms.
- Secure Persistence: (Optional) hooks to save session data in encrypted local storage.
Usage Flow #
graph LR
A[Launch App] --> B[Initialize DAppStore]
B --> C[Connect Wallet]
C --> D[Active Account Stream]
D --> E[Update UI Components]
E --> F[Session Persisted]
ποΈ Architecture #
graph TD
UI[Flutter UI] --> Store[DApp Store]
Store --> Handler[Session Handler]
subgraph Connectors [Abstraction Layer]
Injected[Injected Connector]
WC[Reown Connector]
Local[Private Key Connector]
end
Handler --> Connectors
π Technical Reference #
Core Classes #
| Class | Responsibility |
|---|---|
DAppStore |
The central state hub for the entire application. |
Web3Connector |
Base class for adding new wallet connection methods. |
AccountState |
Immutable snapshot of connected address and chain. |
Eip6963Discovery |
Logic for detecting multiple browser extensions. |
π‘οΈ Security Considerations #
- Session Hijacking: In Web environments, ensure the
originis strictly validated when receiving messages from browser extensions. - Data Leaks: Avoid storing unencrypted private keys in the
DAppStore. Prefer keeping keys in thesignerlayer and only holding the address in theUI Store. - Race Conditions: When switching networks, ensure all pending requests are either cancelled or correctly re-routed to avoid inconsistent UI states.
π» Usage #
Initializing a Reactive Store #
import 'package:dart_web3_dapp/dart_web3_dapp.dart';
void main() {
final store = DAppStore(
connectors: [
MetaMaskConnector(),
ReownConnector(projectId: '...'),
],
);
// Listen for account changes
store.activeAccount.listen((acc) {
print('Current User: ${acc?.address}');
});
store.connect('metamask');
}
π¦ Installation #
dependencies:
dart_web3_dapp: ^0.1.0