solana_kit_mobile_wallet_adapter 0.2.0
solana_kit_mobile_wallet_adapter: ^0.2.0 copied to clipboard
Flutter plugin for the Solana Mobile Wallet Adapter protocol. Enables dApps to communicate with wallet apps for transaction signing on Android. iOS compiles but is a no-op.
solana_kit_mobile_wallet_adapter #
Flutter plugin for the Solana Mobile Wallet Adapter (MWA) protocol. Enables dApps and wallet apps to communicate for transaction signing on Android.
Android-only. MWA is not supported on iOS. This plugin compiles and runs on iOS without crashing (no-op), so mixed-platform Flutter apps work without conditional compilation.
Features #
dApp side (client) #
transact()- One-call session lifecycle: launch wallet, handshake, execute callback, clean upLocalAssociationScenario- Full control over local WebSocket sessions with retry logicRemoteAssociationScenario- Remote sessions via WebSocket reflector (cross-device)KitMobileWallet- Typed API working with base64 payloads and Solana Kit types- Platform check -
isMwaSupported()/assertMwaSupported()
Wallet side (server) #
WalletScenario- Manages incoming dApp connections via native Android bridgeWalletScenarioCallbacks- Interface for handling authorize, sign, and deauthorize requests- Typed request/response -
AuthorizeDappRequest,SignTransactionsRequest, etc. withcompleteWith*methods MobileWalletAdapterConfig- Wallet capabilities (max payloads, features, transaction versions)
Installation #
flutter pub add solana_kit_mobile_wallet_adapter
If you're working inside the solana_kit monorepo, workspace resolution uses local packages automatically.
Documentation #
- Package page: https://pub.dev/packages/solana_kit_mobile_wallet_adapter
- API reference: https://pub.dev/documentation/solana_kit_mobile_wallet_adapter/latest/
Usage #
dApp: Simple session #
import 'package:solana_kit_mobile_wallet_adapter/solana_kit_mobile_wallet_adapter.dart';
import 'package:solana_kit_mobile_wallet_adapter_protocol/solana_kit_mobile_wallet_adapter_protocol.dart';
final authResult = await transact((wallet) async {
// Authorize with the wallet.
final auth = await wallet.authorize(
identity: const AppIdentity(name: 'My dApp'),
chain: 'solana:mainnet',
);
// Sign transactions.
final signed = await wallet.signTransactions(
payloads: [base64EncodedTransaction],
);
return auth;
});
dApp: Manual session control #
final scenario = LocalAssociationScenario();
try {
final rawWallet = await scenario.start();
final wallet = wrapWithKitApi(rawWallet);
final auth = await wallet.authorize(
identity: const AppIdentity(name: 'My dApp'),
chain: 'solana:devnet',
);
final signed = await wallet.signTransactions(
payloads: ['base64tx1', 'base64tx2'],
);
} finally {
await scenario.close();
}
Wallet: Handling requests #
class MyWalletCallbacks implements WalletScenarioCallbacks {
@override
void onAuthorizeRequest(AuthorizeDappRequest request) {
// Show UI to approve/decline.
request.completeWithAuthorize(
accounts: [
AuthorizedAccount(address: base64PublicKey, label: 'Main Account'),
],
authToken: 'issued-token',
);
}
@override
void onSignTransactionsRequest(SignTransactionsRequest request) {
// Sign the payloads.
final signed = signPayloads(request.payloads);
request.completeWithSignedPayloads(signed);
}
// ... implement other callbacks
}
final scenario = WalletScenario(
walletName: 'My Wallet',
config: const MobileWalletAdapterConfig(
maxTransactionsPerSigningRequest: 10,
optionalFeatures: ['solana:signTransactions'],
),
callbacks: MyWalletCallbacks(),
);
await scenario.start();
Platform support #
| Platform | dApp (client) | Wallet (server) |
|---|---|---|
| Android | Supported | Supported |
| iOS | No-op | No-op |
| Web | N/A | N/A |
Use isMwaSupported() to check at runtime before calling MWA APIs.
Architecture #
This plugin uses a hybrid Dart + native approach:
- Dart: All WebSocket handling, P-256 cryptography, session handshake, JSON-RPC messaging, and protocol logic (via
solana_kit_mobile_wallet_adapter_protocol) - Android Kotlin: Intent launching (
solana-wallet://scheme) and wallet scenario bridge (MethodChannel) - iOS Swift: Empty no-op plugin that compiles cleanly
This maximizes code sharing, testability, and reuse of the pure Dart protocol package.
Example #
Use example/main.dart as a runnable starting point for solana_kit_mobile_wallet_adapter.
- Import path:
package:solana_kit_mobile_wallet_adapter/solana_kit_mobile_wallet_adapter.dart - This section is centrally maintained with
mdtto keep package guidance aligned. - After updating shared docs templates, run
docs:updatefrom the repo root.
Maintenance #
- Validate docs in CI and locally with
docs:check. - Keep examples focused on one workflow and reference package README sections for deeper API details.