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/aleph-zero-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 polkadot network using the Nightly object acquired from the previous step, do the following.

// Assuming nightly is the detected Nightly Wallet object
const adapter = nightly.injectedWallet
// polkadotNetwork object is one of these 'Polkadot' | 'AlephZero' | 'Vara'
const inject = await adapter.enable(YOUR_APP_NAME, polkadotNetwork)

// Assert that there is at least one account
if ((await inject.accounts.get()).length <= 0) {
throw new Error('No accounts found')
}
this._innerStandardAdapter = {
...inject,
signer: {
...inject.signer,
signPayload: inject.signer.signPayload
? payload => inject.signer.signPayload(payload, polkadotNetwork)
: undefined,
signRaw: inject.signer.signRaw
? payload => inject.signer.signRaw(payload, polkadotNetwork)
: undefined
}
}

Disconnect​

We recommend setting the adapter object to undefined and rebuilding your app instance.

adapter = undefined

this._appInstance = App.build()