Connect with Polkadot extension
Last updated
Last updated
Before getting started, please ensure that you have the following prerequisites in place:
in the Polkadot{.js} extension, or directly.
Install and configure your preferred code editor (for this tutorial, we will be using Visual Studio Code [VSC]).
Install , along with NPM.
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.
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).
The next step will be to . You can also look at how to or a with your extension.