Skip to main content

Connect Nightly

info

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/aptos-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 wrap the Nightly object acquired from the previous step with an adapter to allow seamless interaction, you should use the StandardWalletAdapter class from the @aptos-labs/wallet-standard.

We recommend calling connect() function, in order to establish connection with Nightly.

import { AptosWallet, NetworkInfo } from '@aptos-labs/wallet-standard';

// Assuming nightly is the detected Nightly Wallet object
const adapter = nightly.standardWallet as AptosWallet;

await adapter.features['aptos:connect'].connect(SILENT_CONNECT, networkInfo);
note

The networkInfo object, which is of type NetworkInfo from @aptos-labs/wallet-standard, is used to specify which aptos network do we want to connect the adapter to. This will be explained further in a chapter - Changing adapter network.

Disconnect

We recommend calling disconnect() function, in order to break connection with Nightly.

await adapter.features['aptos:disconnect'].disconnect()