Skip to main content

Change the adapter network

In Nightly wallet, on the Solana network, there is an option to change the sSVM network adapter-wise. To achieve this, you can use the injected nightly object on the window.

note

Nightly Extension injects itself into the window object once you enter the website. This behavior allows to call the methods, such as changeNetwork() on the injected object.

interface INewSolanaNetwork {
genesisHash: string
url?: string // rpc endpoint of the requested network
}

const newNetwork: INewSolanaNetwork = {
genesisHash: ...,
url: ...
}

window.nightly?.solana?.changeNetwork(newNetwork)
note

Keep in mind the genesis hash must be a valid SVM hash. You can get the genesis hash of any SVM network using the getGenesisHash RPC call.

import { Connection } from '@solana/web3.js'

const connection = new Connection(networkRpc)
const genesisHash = await connection.getGenesisHash()

This should open the popup inside Nightly Extension, prompting the user to change the network.

Check the implementation of this behaviour here, at the end of the file inside the changeNetwork method.

To acquire information about the current network, aka the SVM network the wallet is currently connected to, we can use a getter on the same instance of the injected wallet object, like so.

const activeGenesisHash = window.nightly?.solana?.genesisHash