TERNOA Documentation
Learn Build
  • What is Ternoa Chain ?
  • SPECS
    • Polygon CDK zkEVM
    • Polygon AggLayer
    • Avail DA
    • Trusted Execution Environments 
  • BUILD
    • Wallets
    • RPC
    • API
    • Explorer
  • Tools
    • Staking
    • Ternoa Safe
    • TIP
  • Community
    • Ternoa.com
    • Github
    • Discord
    • Twitter
    • Medium
Powered by GitBook
On this page
  • Prerequisites
  • Next
  1. Build
  2. Javascript SDK
  3. Handling wallets & accounts

Connect with Polkadot extension

Last updated 1 year ago

Prerequisites

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

  1. in the Polkadot{.js} extension, or directly.

  2. Install and configure your preferred code editor (for this tutorial, we will be using Visual Studio Code [VSC]).

  3. Install , 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.

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();
};

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 . You can also look at how to or a with your extension.

sign a transaction in a browser environment
mint an NFT
secret NFT
create an account in the extension
NodeJS v.14+
Import your Ternoa account