Skip to main content

Build & Connect

info

This part of documentation is targeted to clients/wallets that want to enable nightly connect as way of interaction with external applications.

To get started, first we establish Connection with server create(). This enables use interactions with our sessions.

After that we can query session info with getInfo(), which requires 1 argument, sessionId (the one from the QR code).

Once client decides to connect and approves the request, call the connect() method.

export interface AppMetadata {
name: string;
url?: string;
description?: string;
icon?: string;
additionalInfo?: string;
}

interface GetInfoResponse {
responseId: string;
network: Network;
version: Version; // string
appMetadata: AppMetadata;
}

type Connect = {
publicKeys: string[],
sessionId: string,
notification?: Notification | undefined, // for notification purposes
device?: Device | undefined,
metadata?: string | undefined
}

Build & Connect

import { ClientSolana } from '@nightlylabs/nightly-connect-solana'

const client: ClientSolana = await ClientSolana.create({
url: RELAY_ENDPOINT // default: https://nc2.nightly.app
})
const info: GetInfoResponse = await client.getInfo(sessionId)

const message: Connect = {
publicKeys: [
'9mtkm594sexac7G6jct3PZqyEVe3eUWMx6SUcEhYBRxr',
'8MtpTNvQfr7iAWYLjJeyMw19vHw7bx7jrmoamkootfvA'
],
sessionId: sessionId
}
await client.connect(message)

Disconnect

info

Both client and application can initiate disconnection.
Though when it is the client who disconnects, the session will not be terminated.
Only when application disconnects, the session will be closed.