The dynamic client provides an interface to easily interact with and create embedded wallets for your users.

Notice that embedded wallets must be enabled in your environment’s dashboard settings first!

Creating and Getting the Wallet

This interface allows you to check if an embedded wallet exists, fetch the current embedded wallet or create one if it doesn’t yet exist.

See the following example which renders a prompt to create a wallet or renders its address if it already exists:

const EmbeddedWallet: FC = () => {
  const { wallets } = useReactiveClient(client)

  const wallet = wallets.userWallets[0]

  return (
    <View>
      {wallet && wallets.embedded.hasWallet ? (
        <View>Your wallet address: {wallet.address}</View>
      ) : (
        <Button onPress={() => wallets.embedded.createWallet()}>
          Create Wallet
        </Button>
      )}
    </View>
  )
}

Exporting Wallet Keys

If your app uses embedded wallets, you must also make sure to provide your users with some way to export their wallets’ keys to ensure they have absolute control over them.

Dynamic provides a quick and easy way to do so with our embedded wallet key export UI flow!

This flow will export the keys from your primary wallet. See here how to set your primary wallet.

const ExportEmbeddedWalletKeyButtons: FC = () => {
  return (
    <View>
      <TouchableOpacity
        onPress={() =>
          client.ui.wallets.revealEmbeddedWalletKey({
            type: 'private-key',
          })
        }
      >
        Reveal private key
      </TouchableOpacity>

      <TouchableOpacity
        onPress={() =>
          client.ui.wallets.revealEmbeddedWalletKey({
            type: 'recovery-phrase',
          })
        }
      >
        Reveal recovery phrase
      </TouchableOpacity>
    </View>
  )
}

You can read more about the embedded wallets module here.