Wallet Integration

In this section, we will provide sample snippets for you to use to connect to your dApp on Zetrix. Here we provide support for both browser wallet extension connection (Chromium-based browsers only) as well as mobile wallet connection.

Browser wallet extension connection

To use the following snippet, you will have to first install the Zetrix Chrome extension wallet herearrow-up-right. Once you have installed and created (or import) an account, you can initiate connection from your dApp to the browser extension wallet using the zetrix object within the window global object. The following snippet can be used:

window.zetrix.authorize(
  { method: "changeAccounts" }, 
  (resp) => {
    if (resp.code === 0) {
      window.zetrix.authorize(
        { method: "sendRandom", param: { random: "blob" } }, 
        (resAuth) => {
          if (resAuth.code === 0) {
            // Retrieve the necessary info from resp.data and resAuth.data to retrieve the address, signData & publicKey
            sessionStorage.setItem("zetrixAccount", resp.data.address);
            sessionStorage.setItem("isLogin", "true");
          }
        }
      );
    } 
  }
);

Mobile wallet connection

For your dApp to support Zetrix mobile wallet connection, you will have to install the zetrix-connect-wallet-sdkarrow-up-right into your project. In order to test your code, you will have to install the Zetrix mobile walletarrow-up-right which are available on both iOSarrow-up-right and Androidarrow-up-right. For mobile wallet connection to your dApp, the following piece of snippet can be referred (the following snippet are pieces of code written in Vue.js as part of the dApp):

For a complete and latest documented coverage of the functionalities, please refer to the zetrix-connect-wallet-sdkarrow-up-right package documentation.

Last updated