๐Ÿ”Creating 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.

let address: string

portal.onReady(async () => {
    // Check if a wallet already exists
    if (!portal.address) {
        await portal.createWallet()
    }
    
    // Set the address from the `Portal` instance
    address = portal.address
})

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