This repository demonstrates how to integrate and use the Portal iOS and Portal Android SDK in a Flutter application. It provides a complete wallet management interface with backup and recovery capabilities, showcasing a production-ready implementation for developers.
- Complete Wallet Management: Create, backup, and recover wallets
- Token Swapping: Swap tokens using Portal's swap functionality (iOS only)
- Cross-Platform Support: Full iOS and Android implementation
- 🔐 Wallet Creation: Generate wallets with Ethereum and Solana addresses
- 💾 Secure Backup: Password-encrypted wallet backup to Portal servers
- 🔄 Wallet Recovery: Restore wallets using password authentication
- 🔄 Token Swapping: Swap tokens using Portal's swap functionality
- 📱 Cross-Platform: Identical functionality on iOS and Android
- ⚡ Loading States: Professional UI with loading indicators for all operations
- Flutter Setup: Ensure Flutter is installed on your system. Refer to the Flutter installation guide.
- iOS Environment: Xcode must be installed for iOS development.
- Android Environment: Follow the official Flutter guide on setting up Android for Flutter.
- Portal API Key: Obtain your Client API key from the Portal Dashboard.
- Development Environment:
- iOS: macOS with Xcode 14+
- Android: Android Studio with SDK 21+
git clone https://github.com/portal-hq/portal_flutter.git
cd portal_flutterEnsure all required Flutter dependencies are installed:
flutter pub getCreate a lib/secrets.dart file by copying the example file and adding your API keys:
cp lib/secrets_example.dart lib/secrets.dartThen update lib/secrets.dart with your Portal API keys:
class Secrets {
static const String PORTAL_CLIENT_API_KEY = "your-portal-api-key-here";
static const String SWAPS_API_KEY = "your-swaps-api-key-here";
static const String CUSTODIAN_API_KEY = "your-custodian-api-key-here";
}The secrets.dart file is gitignored to keep your API keys secure. The app will automatically use these keys when initializing the Portal SDK and performing token swaps.
Run the Flutter app on your preferred platform:
# Run on iOS simulator
flutter run -d ios
# Run on Android emulator
flutter run -d android
# Run on connected device
flutter run- Create Wallet: Generate a new wallet with Ethereum and Solana addresses
- Backup Wallet: Set a password and backup your wallet
- Recover Wallet: Test wallet recovery using your password
- Swap Tokens: Test token swapping (iOS only)
All native SDK operations are handled through Flutter's MethodChannel system, ensuring seamless communication between Dart and native code.
Initialize the Portal SDK with your API key and configuration options.
Method Channel: portal_flutter/portal
Method: initializePortal
Parameters: {apiKey: String, autoApprove: Boolean}
Returns: {success: boolean, message: string}
Create a new wallet with Ethereum and Solana addresses. Handles existing wallet scenarios gracefully.
Method Channel: portal_flutter/portal
Method: createWallet
Returns: {addresses: {ethereum: String, solana: String}}
Backup wallet using password-based encryption with secure Portal SDK mechanisms.
Method Channel: portal_flutter/portal
Method: backupWallet
Parameters: method: String (e.g., "Password")
Returns: boolean (success status)
Recover previously backed up wallet using password authentication.
Method Channel: portal_flutter/portal
Method: recoverWallet
Parameters: method: String (e.g., "Password")
Returns: {success: boolean, addresses: {ethereum: String, solana: String}}
Secure password handling for all backup and recovery operations.
Method Channel: portal_flutter/portal
Method: setPassword
Parameters: password: String
Returns: boolean (success status)
Check if password-based recovery is available for the current wallet state.
Method Channel: portal_flutter/portal
Method: isPasswordRecoverAvailable
Returns: boolean (availability status)
Swap tokens using Portal's swap functionality (iOS only). Android returns a "not supported" error.
Method Channel: portal_flutter/portal
Method: swap
Parameters: {swapsApiKey: String, chainId: String, buyToken: String, sellToken: String, amount: String}
Returns: {success: boolean, transactionHash: String} (iOS) or error (Android)
Note: The UI provides pre-filled defaults:
- Buy Token: USDC
- Sell Token: ETH
- Amount: 10000000000000 Wei (0.00001 ETH)
- Chain ID: eip155:8453 (Base)
Feature parity between iOS and Android platforms:
- iOS: PortalSwift SDK with Swift (full functionality including swaps)
- Android: Portal Android SDK with Kotlin (wallet management only, swaps not supported in this example so far)
- Flutter: Dart UI layer with MethodChannel communication
- Comprehensive error management across all operations
- User-friendly error messages and recovery suggestions
- Graceful handling of network and SDK errors
- iOS Integration: PortalSwift Flutter iOS Integration Guide
- Android Integration: Portal Android SDK Flutter Integration Guide
- Portal SDK: Official Portal Documentation
- Community: Join the official Portal Community Slack
Ready to integrate Web3 into your app?
- Visit Portal: portalhq.io
- Book a Demo: Schedule a demo
- Developer Resources: Portal Developer Hub


