privy_flutter 0.0.1
privy_flutter: ^0.0.1 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
- Broadcasting Transactions
- Multiple Embedded Wallets
Getting Started #
Requirements #
- Flutter: 3.10.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
Run:
flutter pub get
Configuration #
Registering Your App #
You must configure your App ID and Client ID in the Privy Developer Dashboard.
- iOS: Add your app's Bundle Identifier under Settings → Clients.
- Android: Add your Application ID from
build.gradle
. - Register Allowed URL Schemes for OAuth authentication in
Info.plist
(iOS) andAndroidManifest.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);
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();
Authentication #
Login with Email #
final result = await privy.email.sendCode("user@example.com");
final loginResult = await privy.email.loginWithCode(code: "123456", email: "user@example.com");
Login with Phone #
final result = await privy.sms.sendCode("+14155552671");
final loginResult = await privy.sms.loginWithCode(code: "123456", phoneNumber: "+14155552671");
Login with Custom Auth #
final loginResult = await privy.customAuth.loginWithCustomAccessToken();
Embedded Wallets #
Create an Ethereum Wallet #
final walletResult = await privy.user?.createEthereumWallet();
Create a Solana Wallet #
final walletResult = await privy.user?.createSolanaWallet();
Sign a Message (Solana) #
final signature = await privy.user?.embeddedSolanaWallets.first.provider.signMessage("message");
Logout #
await privy.logout();
Error Handling #
All SDK responses use Result<T>
. Handle success or failure using .fold()
:
result.fold(
onSuccess: (user) => print("Success: ${user.id}"),
onFailure: (error) => print("Error: ${error.message}"),
);
License #
This project is licensed under the MIT License.
For more details, visit the Privy Developer Dashboard.