Documentation
Server
Usage examples
With Constructor

Example usage of the walletAPIServer

Here's how you can instantiate a new WalletAPIServer using its constructor

instantiation

const transport: Transport = {
  onMessage: undefined,
  send: (message: string) => {
    if (wapiView) {
      wapiView.webContents.postMessage("message", message);
    }
  },
};
 
const config = {
  appId: "fake-manifest-id", // should be the real manifest id, used in the storage handler code
  wallet: {
    name: "browserview-wallet",
    version: "0.1.0",
  },
  tracking: false,
  userId: "fake",
};
 
const wapiServer = new WalletAPIServer(transport, config);

two required arguments are passed, transport and config.

setup accounts, currencies and permissions via setters

wapiServer.setAccounts(accounts);
wapiServer.setCurrencies(currencies);
wapiServer.setPermissions({
  currencyIds: ["**"],
  methodIds: ["account.list", "account.receive", "account.request"],
});

Call setters to set the accounts, currencies, and permissions

set wallet handlers

    wapiServer.setHandler("account.request", async ({ accounts$, currencies$ }) => {
      return new Promise((resolve, reject) => {
        uiAccountRequest({
          accounts$,
          currencies: currencies.map({id} => id),
          onSuccess: (account: AccountLike, parentAccount: Account | undefined) => {
            resolve(accountToWalletAPIAccount(account, parentAccount));
          },
          onCancel: () => {
            reject(new Error("Canceled by user"));
          },
        });
      });
    })
 

Set a walletHandler to handle actions that would request an account from the wallet.

wire up transport

import { ipcMain } from "electron";
ipcMain.on("walletAPI:postMessage", (_, data) => {
  transport.onMessage?.(data);
});

Set up the transport's onMessage value, which will allow APP -> SERVER communication.

More on transport here.