Skip to content

Creating the wallet

Privy's embedded wallets are compatible with the Ethereum and Solana blockchains.

To create an embedded wallet for your user, call the createWallet method on your Privy client's embeddedWallet class.

Pass in the following parameters to the createWallet method:

FieldTypeDescription
chainTypeChainTypeSpecifies the chain. Either .ethereum or .solana.
allowAdditionalBool(Optional, Ethereum only) Ethereum embedded wallets are hierarchical deterministic (HD) wallets, and a user's seed entropy can support multiple separate embedded wallets. If a user already has a wallet and you'd like to create additional HD wallets for them, pass in true for the allowAdditional parameter. Defaults to false.

Ethereum Example

swift
// ensure user is authenticated first
guard case .authenticated = authManager.authState else { return }

// Create the primary (HD index == 0) Ethereum wallet
let ethereumWallet = try await privy.embeddedWallet.createWallet(chainType: .ethereum)

// Create an additional (HD index == 1) Ethereum wallet
// If allowAdditional was unset, or set to false, this method would throw an error
let additionalEmbeddedWallet = try await privy.embeddedWallet.createWallet(chainType: .ethereum, allowAdditional: true)

Solana Example

swift
// ensure user is authenticated first
guard case .authenticated = authManager.authState else { return }

// Create a Solana wallet
let solanaEmbeddedWallet = try await privy.embeddedWallet.createWallet(chainType: .solana)

If a wallet is successfully created for the user, privy.embeddedWallet.embeddedWalletState will update.

This method will throw an error if:

  • There is no authenticated user
  • Embedded wallet state is not "connected"
  • If an embedded wallet already exists and allowAdditional was set to false
  • If a user already has 9 or more wallets
  • If the network call to create the wallet fails