# Connect with Polkadot extension

### Prerequisites

Before getting started, please ensure that you have the following prerequisites in place:

1. [Import your Ternoa account](https://docs.ternoa.network/build-1/javascript/wallets/pages/74OQM5fJ55PU0jJHPDl4#how-to-connect-your-ternoa-account-on-polkadot-.js) in the Polkadot{.js} extension, or [create an account in the extension ](/getting-started/wallets/polkadot-extension.md)directly.&#x20;
2. Install and configure your preferred code editor (for this tutorial, we will be using Visual Studio Code \[VSC]).
3. Install [NodeJS v.14+](https://nodejs.org/en/download/), along with NPM.

#### Utilizing Polkadot extension, Next.js, and TypeScript:

In the code snippet below, we cover how to connect to the @polkadot/extension-dapp and fetch your accounts registered in your Polkadot browser extension (it will also fetch all substrate accounts registered in the other browser extensions).

Please, note that this solution is not the only one. **Feel free to use any provider that would suit best your dApp.**

*This code snipped is designed to work in a **Next-js environment**. According to Next-js server-side components rules, the import of the @polkadot/extension-dapp extension library might need to be slightly adapted to work in your javascript environment.*

```typescript
export const getAccounts = async () => {
  const { web3Accounts, web3Enable } = await import("@polkadot/extension-dapp");
  const extensions = await web3Enable("Name your dApp powered by Ternoa");
  if (extensions.length === 0)
    throw new Error(
      'polkadot{.js} extension might not be installed. Make sure you allowed the dApp in the "Manage Website Access" settings of your wallet.'
    );
  return await web3Accounts();
};

```

{% hint style="info" %}
You can implement this **atomic function** in your repository.&#x20;
{% endhint %}

Now you can access the accounts, you can fetch them when needed, and store the index of the account you want to set as the connected account in your storage solution (context, redux, or any solution you use).

### Next

The next step will be to [sign a transaction in a browser environment](/build-1/javascript/ternoa-js-library-utilities/sign-a-transaction-with-polkadot-.js-extension-in-a-browser-environment.md). You can also look at how to [mint an NFT](/build-1/javascript/ternoa-js-library-utilities/sign-a-transaction-with-polkadot-.js-extension-in-a-browser-environment.md) or a [secret NFT](/build-1/javascript/privacy-protocols/tee-privacy-and-encryption/encryption-in-browser-with-wallet-and-extension.md) with your extension.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ternoa.network/build-1/javascript/wallets/connect-with-polkadot-extension.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
