LogoLogo
SupportGithubSign InGet Access
  • Introduction
  • GETTING STARTED
    • SDK Quick Start
    • API Quick Start
  • Guides
    • Web
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Web authentication methods
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Configure a custom subdomain
      • Eject a wallet
      • Using the EIP-1193 Provider
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • iOS
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Manage ERC20 tokens
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
          • Passkey + Enclave Storage
        • Recover a wallet
      • Troubleshooting Tips
      • Feature Flags
    • Android
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • React Native
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • Enclave MPC API
      • Create a client
      • Create a wallet
      • Send tokens
      • Sign Ethereum transactions
      • Sign Solana transactions
      • Sign Tron transactions
      • Sign Stellar Transaction
      • Concurrent Transactions
      • Back up a wallet
      • Eject a wallet
  • Reference
    • iOS
      • createWallet
      • backupWallet
      • recoverWallet
      • ejectPrivateKeys
      • registerBackupMethod
      • setGDriveConfiguration
      • setPasskeyConfiguration
      • setPasskeyAuthenticationAnchor
      • setPassword
      • availableRecoveryMethods
      • doesWalletExist
      • isWalletBackedUp
      • isWalletOnDevice
      • isWalletRecoverable
      • getBalances
      • getAssets
      • getNftAssets
      • getTransactions
      • sendSol
      • evaluateTransaction
      • buildEip155Transaction
      • buildSolanaTransaction
      • getWalletCapabilities
    • Android
      • Reference Documentation
    • React Native
      • @portal-hq/core
      • Storage adapters
        • Cloud storage
          • @portal-hq/gdrive-storage
          • @portal-hq/icloud-storage
        • Mobile storage
          • @portal-hq/keychain
          • @portal-hq/mobile-key-values
    • Enclave MPC API
      • V1 endpoints
    • Client API
      • V3 endpoints
      • V1 endpoints
    • Custodian API
      • V3 endpoints
      • V1 endpoints
    • Swaps API
      • V3 endpoints
      • V1 endpoints
  • Resources
    • Flutter
      • iOS
      • Android
    • Error codes
      • Overview
      • Legacy Documentation
        • MPC errors
        • Network errors
        • General errors
        • Encryption errors
        • Portal Connect errors
    • Portal's MPC architecture
    • Authentication and API Keys
    • Self-Managed Backups
    • Alert Webhooks
    • Wallet lifecycle
    • Backup options
      • Password/PIN
      • GDrive
      • iCloud
      • Passkey + Enclave
    • WalletConnect metadata
    • Advanced security scanning
    • Account abstraction
    • Security firewall
    • Eject
    • Security
    • Blockchain support
    • Chain ID formatting
    • Testnet faucets
    • Going to Production
    • Rate Limits
    • Multi-backup migration guide
    • Multi-wallet migration guides
      • Migrating from Android SDK v3.x.x to v4.x.x
      • Migrating from iOS SDK v3.0.x to v3.2.x
  • Support
    • Changelog
      • Android
      • iOS
      • React Native
      • Web
      • Past Releases
        • 2024 Releases
        • 2023 Releases
    • Celo Hackathon Hub
    • Glossary
Powered by GitBook
On this page
  • Installation
  • Initializing Portal

Was this helpful?

Edit on GitHub
  1. Guides

Android

PreviousFeature FlagsNextCreate a wallet

Last updated 3 months ago

Was this helpful?

Portal provides MPC wallets and dApp connections for organizations and their users. To integrate Portal, an organization adds a client library to their mobile app and a few server API endpoints.

Installation

Update the dependencies in your build.gradle to include the portal-android dependency

// In your app/build.gradle file
...
dependencies {
    ...
    implementation "io.portalhq.android:portal-android:X.X.X"
}

Initializing Portal

After you update your build.gradle file, you must sync gradle and you're ready to import Portal into an Activity of your choice.

With the Portal Android dependency now installed, we can now create an instance of the Portal class. Below is an example of how you can do this. In this example, we're using your app's MainActivity.

package io.portal.android.app
 
import io.portal.android.Portal
import io.portal.android.storage.cloud.google.GoogleStorage
import io.portal.android.storage.mobile.Keychain

class MainActivity : AppCompatActivity() {
    lateinit val portal: Portal
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // Initialize your Portal instance.
        portal = Portal(
            // A Portal client API key. You can obtain one from Portal's REST API.
            apiKey = CLIENT_API_KEY,
            // A map of chainIDs to Gateway URLs (e.g. Infura, Alchemy, etc.)
            rpcConfig = mapOf("eip155:11155111" to YOUR_GATEWAY_URL),
            // A boolean to auto-approve transactions.
            autoApprove = true,
            //Optional: Only provide Eth chain id here if you are upgrading from V3 otherwise skip this. This is needed for some legacy code
            legacyEthChainId = 11155111
        )
        
        // Configure Backup with GDrive
        portal.configureGoogleStorage(
          GDriveConfiguration(
              clientId = YOUR_GDRIVE_CLIENT_ID, // Your Google client id with GDrive access
              signOutAfterUse = true // Signout Google after backup/recover operation,
              gDriveBackupOption = GDriveBackupOption.AppDataFolder // this mode specifies where the backup key is stored in GDrive. Will be explained later in GDrive backup guides
          )
        )
        
    }
}

package io.portalhq.android.app

import io.portalhq.android.Portal
import io.portalhq.android.storage.cloud.google.GoogleStorage
import io.portalhq.android.storage.mobile.Keychain

class MainActivity : AppCompatActivity() {
    lateinit val portal: Portal
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // 👇 Don't forget to replace below with your own Google Client ID.
        val gDrive = GoogleStorage(YOUR_GOOGLE_CLIENT_ID, signoutAfterUse = true)
        val backupOptions = BackupOptions(gdrive = gDrive)
        val keychain = Keychain(applicationContext)
    
        // Initialize the Portal instance
        portal = Portal(
            // A Portal client API key. You can obtain one from Portal's REST API.
            apiKey = CLIENT_API_KEY,
            // Provide this if you want to implement backup yourself
            backup = null,
            // The EVM network chain ID.
            chainId = 11155111,
            // An instance of Portal's Keychain.
            keychain = keychain,
            // A map of chainIDs to Gateway URLs (e.g. Infura, Alchemy, etc.)
            gatewayConfig = mapOf(5 to YOUR_GATEWAY_URL),
            // Provide configuration of backup options you want to use with Portal
            backupOptions = backupOptions
        )
    }
}

}

Now that we have our Portal instance, the next step is to generate a wallet. Let's create one!

When your user's CST expires, all Portal SDKs will throw an error on the next MPC Operation the user makes (e.g. creating a wallet, backing up a wallet, recovering a wallet, or signing). For Android, the SDK will throw PortalHttpUnauthorizedException which you can use as an indicator to refresh your CST.

If you are using , this hint is for you.

Client Session Tokens (CSTs)
The Portal library connects your mobile app and server with the web3 ecosystem.