privy_flutter 0.0.3 copy "privy_flutter: ^0.0.3" to clipboard
privy_flutter: ^0.0.3 copied to clipboard

Privy Flutter SDK enables seamless authentication, wallet management, and identity verification for Flutter apps with native iOS and Android support.

Privy Flutter SDK #

The Privy Flutter SDK is a Flutter plugin that connects your application to native Privy SDKs for iOS and Android. It enables authentication, non-custodial embedded wallets, and user management by leveraging Privy's platform-specific capabilities.

Features #

Authentication #

  • Login with Phone
  • Login with Email
  • Login with Custom Auth

Embedded Wallets (Ethereum & Solana) #

  • Wallet Creation
  • Automatic Recovery
  • Signing Messages & Transactions

Ethereum-Only Features

  • Broadcasting Transactions
  • Multiple Embedded Wallets

Getting Started #

Requirements #

  • Flutter: 3.24.0+
  • Dart: 3.0.0+
  • Android: API 27+ (8.1 Oreo or newer)
  • iOS: 16+

Installation #

Add the latest Privy SDK dependency to your pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  privy_flutter: ^0.0.1  # Replace with the latest version
copied to clipboard

Run:

flutter pub get
copied to clipboard

Configuration #

Registering Your App #

You must configure your App ID and Client ID in the Privy Developer Dashboard.

  1. iOS: Add your app's Bundle Identifier under Settings → Clients.
  2. Android: Add your Application ID from build.gradle.
  3. Register Allowed URL Schemes for OAuth authentication in Info.plist (iOS) and AndroidManifest.xml (Android).

Initialization #

Import and configure Privy in your Flutter app:

import 'package:privy_flutter/privy_flutter.dart';

final privyConfig = PrivyConfig(
  appId: "YOUR_APP_ID",
  appClientId: "YOUR_CLIENT_ID",
);

final privy = Privy(config: privyConfig);
copied to clipboard

Await SDK Readiness #

When the Privy SDK is initialized, the user's authentication state will be set to NotReady until Privy finishes initialization. During this time, we suggest you show a loading state to your user. For you convenience, we've added a suspending awaitReady() function. Here's an example with some pseudocode:

await privy.awaitReady();
copied to clipboard

Authentication #

Login with Email #

Authenticate users via email-based OTP verification.

Step 1: Send OTP to User’s Email

final result = await privy.email.sendCode("user@example.com");
copied to clipboard
  • Success(): OTP was sent successfully.
  • Failure(PrivyException): Error sending OTP.

Step 2: Verify OTP and Login

final loginResult = await privy.email.loginWithCode(code: "123456", email: "user@example.com");
copied to clipboard
  • Success(PrivyUser): User authenticated successfully.
  • Failure(PrivyException): Invalid OTP or authentication failed.

Login with Phone #

Authenticate users via SMS-based OTP verification.

Step 1: Send OTP to User’s Phone Number

final result = await privy.sms.sendCode("+14155552671");
copied to clipboard
  • Success(): OTP was sent successfully.
  • Failure(PrivyException): Error sending OTP.

Step 2: Verify OTP and Login

final loginResult = await privy.sms.loginWithCode(code: "123456", phoneNumber: "+14155552671");
copied to clipboard
  • Success(PrivyUser): User authenticated successfully.
  • Failure(PrivyException): Invalid OTP or authentication failed.

Login with Custom Auth #

Authenticate users using a third-party authentication provider.

final loginResult = await privy.customAuth.loginWithCustomAccessToken();
copied to clipboard
  • Success(PrivyUser): User authenticated successfully.
  • Failure(PrivyException): Invalid or expired token.

Get Access Token #

Retrieve the user's authentication token for API requests.

final getAccessTokenResult = await privy.user?.getAccessToken();
copied to clipboard
  • Success(String): Token retrieved successfully.
  • Failure(PrivyException): User not authenticated or error occurred.

Embedded Wallets #

Create an Ethereum Wallet #

Creates a non-custodial Ethereum embedded wallet for the user.

final walletResult = await privy.user?.createEthereumWallet();
copied to clipboard
  • Success(EmbeddedEthereumWallet): Wallet created successfully.
  • Failure(PrivyException): User not authenticated, network error, or wallet limit exceeded.

Create a Solana Wallet #

Creates a non-custodial Solana embedded wallet for the user.

final walletResult = await privy.user?.createSolanaWallet();
copied to clipboard
  • Success(EmbeddedSolanaWallet): Wallet created successfully.
  • Failure(PrivyException): User not authenticated or network error.

Sign a Message (Solana) #

Sign a message using the user’s Solana embedded wallet.

final signature = await privy.user?.embeddedSolanaWallets.first.provider.signMessage("message");
copied to clipboard
  • Success(String): Signature generated successfully.
  • Failure(PrivyException): User not authenticated or wallet not found.

Logout #

Logs the user out and clears the persisted session.

await privy.logout();
copied to clipboard
  • Success(): User logged out successfully.
  • Failure(PrivyException): Error during logout.

Error Handling #

All SDK responses use Result<T>. Handle success or failure using either .fold() or a switch statement.

Using .fold() #

The .fold() method allows you to execute separate callbacks for success and failure.

result.fold(
  onSuccess: (user) => print("Success: ${user.id}"),
  onFailure: (error) => print("Error: ${error.message}"),
);
copied to clipboard

Using a switch Statement #

Alternatively, you can use a switch statement to handle success and failure.

switch (result) {
  case Success(:final user): // Extracts `user` from Success<T>
    print("Success: ${user.id}");
    break;
  
  case Failure(:final error): // Extracts `error` from Failure<T>
    print("Error: ${error.message}");
    break;
}
copied to clipboard

License #

This project is licensed under the MIT License.


For more details, visit the Privy Developer Dashboard.

1
likes
140
points
590
downloads

Publisher

verified publisherprivy.io

Weekly Downloads

2024.09.13 - 2025.03.28

Privy Flutter SDK enables seamless authentication, wallet management, and identity verification for Flutter apps with native iOS and Android support.

Homepage
Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface, rxdart

More

Packages that depend on privy_flutter