Skip to main content

Connect Nightly

This part of documentation assumes you have already completed the detection step and have

access to the Nightly wallet object. :::


To view the implementation of the connect method, and the ones described in the later chapters, visit our source code.

Source code: https://github.com/nightly-labs/solana-web3-template/blob/main/app/components/StickyHeader.tsx


In order to start using Nightly extension, an app needs to establish a connection. Once the connection request is initiated on the application side, it will prompt the user to provide permission to connect to the app with Nightly.


Connect

To connect with the wallet inside the dApp we recommend calling connect() metod on the features object, like so.

const accounts = await window.nightly.solana.features['standard:connect'].connect(silent)
info

The connect function is typed like this

import type { WalletAccount } from '@wallet-standard/base';

export interface StandardConnectInput {
// pass the silent parameter if you want to request already authorized accounts, without prompting
readonly silent?: boolean;
}

export interface StandardConnectOutput {
readonly accounts: readonly WalletAccount[];
}

export type StandardConnectMethod = (input?: StandardConnectInput) => Promise<StandardConnectOutput>;

as required by the @wallet-standard/features

For more info, refer here.

You can also wrap the Nightly object acquired from the detection step with an adapter to allow seamless interaction. To do so you should use the StandardWalletAdapter class from the @solana/wallet-standard and, if you are using typescript, @solana/wallet-adapter-base to conform with the adapter types.

Then, call the connect() function, in order to establish connection with Nightly.

import { StandardWalletAdapter } from "@solana/wallet-standard";
import { WalletAdapterCompatibleStandardWallet } from "@solana/wallet-adapter-base";

const adapter = new StandardWalletAdapter({
// Assuming nightly is the detected Nightly Wallet object
wallet: nightly.standardWallet as WalletAdapterCompatibleStandardWallet,
});

await adapter.connect();

Disconnect

As for the disconnect process, we again recommend using the features oriented flow, like so

window.nightly.solana.features['standard:disconnect'].disconnect()

Otherwise, if you are using the wrapper, call disconnect() function, in order to break connection with Nightly.

await adapter.disconnect()