Skip to main content

Para Class

The Para class is the main entry point for the Para Flutter SDK, providing wallet operations, authentication, and blockchain interactions. The latest version includes passkey authentication, comprehensive multi-chain support, and deep linking capabilities.

Constructor

Para.fromConfig()
Constructor
Creates a new Para SDK instance using the v2 factory constructor.
final para = Para.fromConfig(
  config: ParaConfig(
    environment: Environment.beta,
    apiKey: 'YOUR_API_KEY',
    jsBridgeUri: Uri.parse('custom-bridge-url'), // Optional
    relyingPartyId: 'custom.domain.com',         // Optional
  ),
  appScheme: 'yourapp',
);

Authentication Methods

initiateAuthFlow()
Future<AuthState>
Initiates authentication flow for email or phone. Returns an AuthState indicating next steps.
// Email authentication
final authState = await para.initiateAuthFlow(
  auth: Auth.email('user@example.com')
);

// Phone authentication
final authState = await para.initiateAuthFlow(
  auth: Auth.phone('+1234567890')
);
verifyOtp()
Future<AuthState>
Verifies the OTP code sent to email/phone during authentication.
final verifiedState = await para.verifyOtp(
  otp: '123456'
);
handleLogin()
Future<Wallet>
Handles login for existing users with passkey authentication.
final wallet = await para.handleLogin(
  authState: authState,
);
handleSignup()
Future<Wallet>
Handles the complete signup flow for new users, including passkey creation and wallet setup.
final wallet = await para.handleSignup(
  authState: authState,
  method: SignupMethod.passkey,
);
verifyOAuth()
Future<AuthState>
Handles complete OAuth authentication flow using an external browser.
final authState = await para.verifyOAuth(
  provider: OAuthMethod.google,
  appScheme: 'yourapp',
);

Wallet Management

createWallet()
ParaFuture<Wallet>
Creates a new wallet with enhanced multi-chain support. Returns a ParaFuture that can be cancelled.
final walletFuture = para.createWallet(
  type: WalletType.evm,
  skipDistribute: false,
);

final wallet = await walletFuture.future;
// Or cancel: await para.cancelOperationById(walletFuture.requestId);
fetchWallets()
ParaFuture<List<Wallet>>
Retrieves all wallets for the current user.
final walletsFuture = para.fetchWallets();
final wallets = await walletsFuture.future;

Signing Operations

signMessage()
ParaFuture<SignatureResult>
Signs a message with the specified wallet. Returns a cancellable ParaFuture.
// Generic message signing
final signatureFuture = para.signMessage(
  walletId: wallet.id,
  messageBase64: base64Encode(utf8.encode('Hello, Para!')),
);

final signature = await signatureFuture.future;

// Cosmos transaction signing
final cosmosSignature = await para.signMessage(
  walletId: cosmosWallet.id,
  messageBase64: '', // Not used for Cosmos
  cosmosSignDocBase64: base64Encode(utf8.encode(jsonEncode(signDoc))),
).future;
signTransaction()
ParaFuture<SignatureResult>
Signs an EVM transaction. Returns a cancellable ParaFuture.
This method is for EVM transactions only. For Solana, use signMessage() with the serialized transaction as messageBase64. For Cosmos, use signMessage() with cosmosSignDocBase64.EVM Transaction Return Value: The SuccessfulSignatureResult contains the complete RLP-encoded transaction ready for broadcasting via the signedTransaction property.Solana/Cosmos Return Value: For pre-serialized transactions, returns just the signature in signedTransaction. For constructed transactions, returns the complete signed transaction.
// EVM transaction signing
final signatureFuture = para.signTransaction(
  walletId: evmWallet.id,
  rlpEncodedTxBase64: base64Encode(rlpEncodedTx),
  chainId: '1', // Ethereum mainnet
);

final signature = await signatureFuture.future;
cancelOperationById()
Future<void>
Cancels an ongoing operation by its request ID.
final signatureFuture = para.signMessage(...);
// Cancel the operation
await para.cancelOperationById(signatureFuture.requestId);

Session Management

isSessionActive()
ParaFuture<bool>
Checks if there’s an active user session.
final isActive = await para.isSessionActive().future;
exportSession()
ParaFuture<String>
Exports the current session as an encrypted string.
final sessionData = await para.exportSession().future;
// Save sessionData securely
logout()
ParaFuture<void>
Logs out the current user and clears session data.
await para.logout().future;

Utility Methods

getCurrentUserAuthDetails()
ParaFuture<AuthState?>
Gets the current user’s authentication details.
final authDetails = await para.getCurrentUserAuthDetails().future;
waitForLogin()
ParaFuture<Map<String, dynamic>>
Waits for an ongoing login operation to complete.
final result = await para.waitForLogin(
  pollingIntervalMs: 1000,
).future;
waitForWalletCreation()
ParaFuture<Map<String, dynamic>>
Waits for wallet creation to complete after signup.
final result = await para.waitForWalletCreation(
  pollingIntervalMs: 1000,
).future;
formatPhoneNumber()
String?
Formats a phone number for authentication.
final formatted = para.formatPhoneNumber('1234567890', '1');
// Returns: '+11234567890' (exact format depends on implementation)
isUsingExternalWallet()
ParaFuture<bool>
Checks if the current user is using an external wallet.
final isExternal = await para.isUsingExternalWallet().future;
clearStorage()
ParaFuture<void>
Clears local storage data.
await para.clearStorage(false).future;
dispose()
void
Disposes of SDK resources. Call when the SDK is no longer needed.
para.dispose();

Extension Methods

Para provides extension methods for cleaner authentication flows (requires importing extensions):
import 'package:para/src/auth_extensions.dart';

ParaAuthExtensions

initiateAuthFlow()
Future<AuthState>
Initiates authentication and returns the current state using Auth helper class.
// Must import extensions
import 'package:para/src/auth_extensions.dart';

final authState = await para.initiateAuthFlow(
  auth: Auth.email('user@example.com')
);
presentPasswordUrl()
Future<Uri?>
Presents a password authentication URL in a secure web view.

Types and Enums

Environment

enum Environment {
  dev,      // Development environment
  beta,     // Beta environment
  prod      // Production environment
}

Auth

class Auth {
  static AuthEmail email(String email);
  static AuthPhone phone(String phoneNumber);
}

AuthState

class AuthState {
  final AuthStage stage;           // Current authentication stage
  final String? userId;            // User's unique identifier
  final AuthIdentity auth;         // Authentication identity details
  final String? displayName;       // User's display name
  final String? pfpUrl;           // Profile picture URL
  final String? username;         // Username
  final Map<String, dynamic>? externalWallet; // External wallet info
  final String? passkeyUrl;       // URL for passkey authentication
  final String? passkeyId;        // Passkey identifier
  final String? passwordUrl;      // URL for password authentication
  // Additional properties for specific auth flows
}

class AuthIdentity {
  final String? email;
  final String? phoneNumber;
  final String? fid;              // Farcaster ID
  final String? telegramUserId;
  // Other identity types
}

enum AuthStage {
  verify,  // Need to verify email/phone
  login,   // Existing user, proceed to login
  signup   // New user, proceed to signup
}

SignupMethod

enum SignupMethod {
  passkey,  // Hardware-backed passkey
  password  // Password-based authentication
}

OAuthMethod

enum OAuthMethod {
  google,
  twitter,
  apple,
  discord,
  facebook
}

WalletType

enum WalletType {
  evm,     // Ethereum and EVM-compatible chains
  solana,  // Solana blockchain
  cosmos   // Cosmos-based chains
}

ParaFuture

class ParaFuture<T> {
  final Future<T> future;    // The actual future
  final String requestId;    // ID for cancellation
}

Wallet

class Wallet {
  final String id;
  final String address;
  final WalletType type;
  final WalletScheme scheme;
  final String? userId;         // Associated user ID
  final DateTime? createdAt;    // Creation timestamp
  final String? publicKey;      // Wallet public key
  final bool? isPregen;         // Whether this is a pregenerated wallet
  // Additional optional fields available
}

SignatureResult

// Abstract base class
abstract class SignatureResult {}

// Successful signature
class SuccessfulSignatureResult extends SignatureResult {
  final String signedTransaction;  // For transactions: complete signed transaction ready for broadcasting
                                   // For messages: just the signature
  
  SuccessfulSignatureResult(this.signedTransaction);
  
  /// Gets the transaction data ready for broadcasting.
  String get transactionData => signedTransaction;
}

// Denied signature
class DeniedSignatureResult extends SignatureResult {
  final String? pendingTransactionId;
  DeniedSignatureResult(this.pendingTransactionId);
}

// Denied with URL
class DeniedSignatureResultWithUrl extends SignatureResult {
  final String? pendingTransactionId;
  final String url;
  DeniedSignatureResultWithUrl({this.pendingTransactionId, required this.url});
}
I