Skip to content

merigo-labs/solana-wallet-adapter

Repository files navigation

Dart implementation of Solana's Mobile Wallet Adapter Specification protocol. The protocol exposes functionalities of Android and iOS wallet apps (e.g. Solflare) to dapps.


Authorize App


Screenshot of solana_wallet_provider


Non-privileged Methods

Non-privileged methods do not require the current session to be in an authorized state to invoke them.


Privileged Methods

Privileged methods require the current session to be in an authorized state to invoke them. For details on how a session enters and exits an authorized state, see the non-privileged methods.


Setup

Connect your wallet application (e.g. Phantom) and SolanaWalletAdapter to the same network. The wallet application may not support localhost.


Example: Authorize

import 'package:flutter/material.dart';
import 'package:solana_wallet_adapter/solana_wallet_adapter.dart';

void main() {
  runApp(const MaterialApp(
    home: Scaffold(
      body: Center(
        child: AuthorizeButton(),
      ),
    ),
  ));
}

// 1. Create instance of [SolanaWalletAdapter].
final adapter = SolanaWalletAdapter(
  const AppIdentity(),
  // NOTE: CONNECT THE WALLET APPLICATION 
  //       TO THE SAME NETWORK.
  cluster: Cluster.devnet,
);

class AuthorizeButton extends StatefulWidget {
  const AuthorizeButton({super.key});
  @override
  State<AuthorizeButton> createState() => _AuthorizeButtonState();
}

class _AuthorizeButtonState extends State<AuthorizeButton> {
  Object? _output;
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        TextButton(
          onPressed: () {
            // 2. Authorize application with wallet.
            adapter.authorize()
              .then((result) => setState(() => _output = result.toJson()))
              .catchError((error) => setState(() => _output = error));
          },
          child: const Text('Authorize'),
        ),
        if (_output != null)
          Text(_output.toString()),
      ],
    );
  }
}

Bugs

Report a bug by opening an issue.

Feature Requests

Request a feature by raising a ticket.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published