Create a wallet

The first step to the MPC process is generating key shares, or a wallet, for your users.

Once you have an instance of Portal, you can add logic to create web3 wallets.

The onReady hook

The Portal class dynamically loads a number of resources behind the scenes to enable MPC directly in the browser. For this reason, some functionality is not immediately available after initialization.

We have include an onReady function to enable you to write your application logic in a more linear manner without having to explicitly poll the ready state of your Portal instance.

portal.onReady(() => {
    // Your code
})

Wallet Creation

The createWallet function initiates the MPC process to create a set of shares. The user's share and the wallet address is automatically stored in the browser's local storage, but hidden from the main browser context of your web application.

portal.onReady(async () => {
    const walletExists = await portal.doesWalletExist()

    if (!walletExists) {
        await portal.createWallet()
    }
    
    const ethAddress = await portal.getEip155Address()
    const solAddress = await portal.getSolanaAddress()
})

Be sure to use a Production API key when creating clients for production. Read more details about going to production here.

That's it! You now have an MPC Wallet built into your web application.

Last updated