If you don’t have a Portal instance already, we recommend reading this page first.
In the MPC wallet creation process, two sets of key shares are generated. The signing key shares are used for signing transactions, and the backup key shares are used for recovery if the device storing a signing key share is lost.
The portal.createWallet command initiates the MPC process to create a set of shares. The users’ signing shares are automatically stored in the user’s secure phone storage.
import 'package:portal_flutter/portal_flutter.dart';
final portal = Portal();
// Create the wallet.
// Obtain the Ethereum and Solana addresses of the user's new wallet.
final addresses = await portal.createWallet();
print('My Portal EVM address: ${addresses.ethereum}');
print('My Portal Solana address: ${addresses.solana}');
Be sure to use a Production API key when creating clients for production. Read more details about going to production here.
WARNING: To create a wallet with the Portal SDK, your device must be configured to use passcode authentication. If you change your passcode, your Portal wallet will continue to operate as expected. However, if you disable passcode authentication after running the createWallet function, you will be required to execute the recoverWallet function before you can continue using your Portal wallet.
Checking for Existing Wallets
Before creating a new wallet, you may want to check if one already exists:
// Check if a wallet exists on the device
final exists = await portal.doesWalletExist();
if (exists) {
// Get existing addresses
final result = await portal.getAddresses();
if (result.hasWallet) {
print('Existing wallet found');
print('EVM address: ${result.addresses.ethereum}');
print('Solana address: ${result.addresses.solana}');
}
} else {
// Create a new wallet
final addresses = await portal.createWallet();
print('New wallet created');
}
Getting a Specific Chain Address
You can also get the address for a specific chain:
// Get the address for Ethereum mainnet
final ethAddress = await portal.getAddress('eip155:1');
// Get the address for Solana mainnet
final solAddress = await portal.getAddress('solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp');
Now that you’ve created your user’s wallet, let’s try to send a transaction with it!
Related Documentation