Connect with Polkadot extension
Prerequisites
Before getting started, please ensure that you have the following prerequisites in place:
Import your Ternoa account in the Polkadot{.js} extension, or create an account in the extension directly.
Install and configure your preferred code editor (for this tutorial, we will be using Visual Studio Code [VSC]).
Install NodeJS v.14+, 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.
You can implement this atomic function in your repository.
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. You can also look at how to mint an NFT or a secret NFT with your extension.
Last updated