Skip to content
Helpers

Wallets

List the wallets that can sign on the cluster, connect one, handle wallets that sign only version 0, or bring a signer of your own.

The SDK finds wallets through the Wallet Standard, which every major Solana browser wallet supports. You need no wallet adapter library.

In this guide, Alice picks her wallet from a list, connects it, and gets the signer her session needs.

List the wallets

listWallets returns the installed wallets that can do everything the SDK asks. Each one must connect, sign messages and sign transactions on the SDK's cluster. Any other wallet is left out.

import {  } from "@umbra/nimbus-solana-web";

for (const  of ()) {
  .(., .);
}

Each entry is a Wallet Standard Wallet. Show its name and icon in your wallet picker.

Follow wallets that load late

A browser extension can register its wallet after your page loads. followWallets calls you with the new list each time a wallet registers or unregisters. It returns a function that stops following.

In React, a hook keeps the list current:

import { ,  } from "@umbra/nimbus-solana-web";
import { ,  } from "react";

export function (: NimbusSdk): readonly Wallet[] {
  const [, ] = (() => ());
  (() => (, { :  }), []);
  return ;
}

The stop function is the effect's cleanup. The hook stops following when the component unmounts.

Connect one

When Alice picks a wallet, call openWalletConnection. Her wallet shows its connection prompt, unless your page is already connected.

import {  } from "@umbra/nimbus-solana-web";

const  = await (, {  });

switch (.) {
  case "connected": {
    const { ,  } = .;
    .(.., );
    break;
  }
  case "no-account":
    .(`${.} has no account on this network.`);
    break;
  case "declined":
    .("You declined to connect.");
    break;
}
kindWhat happenedWhat to do
connectedThe wallet connected. connected.signer is what a session takes.Open a session.
no-accountThe wallet connected but has no account on this cluster.Ask Alice to add one, or pick another wallet.
declinedAlice refused to connect.Let her try again.

A wallet that fails while connecting throws a NimbusSdkError with reason wallet-unsupported. Ask Alice to pick another wallet.

Version 0 and version 1 wallets

connected.transactionVersion is the newest transaction version the wallet signs. It is 1 for most wallets, and 0 for older ones.

It matters only for the payments Alice's own wallet signs: registration, deposit and a deposit refund. Pass it to each as the transactionVersion option. The default is 1, which a version 0 wallet cannot sign.

At version 0, a deposit takes two transactions, so Alice approves twice. Wallets that sign only version 0 explains why.

A Private Send or a withdrawal is sent by a relayer. Alice's wallet never signs it, so those take no version.

Bring your own signer

A session takes any WalletStandardSigner. That is an account and two functions, shaped like the Wallet Standard's solana:signMessage and solana:signTransaction. Build one when your app already connects wallets through another library, or uses an embedded wallet.

import type { WalletStandardSigner } from "@umbra/nimbus-solana-web";

const : WalletStandardSigner = {
  : {
    : ,
    : ,
    : ["solana:mainnet"],
    : ["solana:signMessage", "solana:signTransaction"],
  },
  : async (...) =>
    .(
      .(async ({  }) => ({
        : ,
        : await (),
      })),
    ),
  : async (...) =>
    .(
      .(async ({  }) => ({
        : await (),
      })),
    ),
};

The SDK holds your signer to the same rules as a wallet:

  • The account lists the cluster's chain, solana:mainnet. Its address is the base58 form of its 32-byte public key.
  • signMessage signs the bytes exactly as given, and returns them as signedMessage. A signer that wraps or prefixes the message is refused as wallet-unsupported.
  • signTransaction returns the whole signed transaction. If it changes the transaction, the payment throws a NimbusSolanaFlowError with reason transaction-altered. Nothing is sent.
  • When the user refuses, reject with an error whose code is 4001. A message that says rejected, declined, denied or cancelled works too. The SDK then answers declined instead of throwing.

Next

Last updated

On this page