Detect Nightly
In order to detect Nightly Wallet in your polkadot app we recommend you use the !polkadot/extension-inject/types and, if you are using typescript, @wallet-standard/core packages, like so.
Before fetching detected wallets, install the packages by running the following command in your terminal
# Using NPM
npm i @polkadot/[email protected]
npm i @wallet-standard/core
# Using Yarn
yarn add @polkadot/[email protected]
yarn add @wallet-standard/core
After installing the packages use this code to get access to all detected wallets.
In case you want to use typescript, you ought to include the following declarations.
import { Injected, InjectedExtension } from '@polkadot/extension-inject/types'
import { WalletIcon } from '@wallet-standard/core'
export interface PolkadotWalletInjected {
connect?: (origin: string) => Promise<InjectedExtension>
enable?: (origin: string) => Promise<Injected>
version?: string
name: string
slug: string
icon?: WalletIcon
}
declare global {
interface Window {
injectedWeb3?: { [key in string]: PolkadotWalletInjected }
}
}
The function to retrieve and parse injected wallet should look like this.
export const getPolkadotWallets = (): PolkadotWalletInjected[] => {
if (window && window.injectedWeb3) {
return Object.entries(window.injectedWeb3).map(([key, value]) => ({
...value,
name: value.name ?? key, // value.name might be undefined
slug: key,
icon: value.icon ?? "https://registry.nightly.app/networks/polkadot.png",
}));
} else {
return [];
}
};
Then you can get all polkadot injected wallets like so.
const polkadotWallets = getPolkadotWallets()
Now, after finding the Nightly wallet in the polkadotWallets
object, you will have access to all of the functions such as connect
, which we will talk about in the next section.
Accessing the nightly object is also possible by finding the nightly.polkadot
object on the window.
const nightlyPolkadot = window.nightly?.polkadot