Provider Activation

Provider Activation

A chain provider allows you to interact with any available network. In this guide, you will learn how to obtain a chain provider and activate it.

Tip

With the Stargazer Extension installed you can test the following examples in the browser console (devtoolsarrow-up-right).

Detect Stargazerarrow-up-right

The Stargazer browser extension injects a WalletProvider instance under window.stargazer each time a page loads. You can check the existence of this property using the following snippet.

TypeScript

if (window.stargazer) {
  console.log("Stargazer version " + window.stargazer.version + " detected");
} else {
  console.log("Stargazer not detected");
}

Copy

Obtain a ChainProviderarrow-up-right

Once you've verified your app has access to a WalletProvider instance you can obtain a ChainProvider to interact with a network of your choice (Constellation or Ethereum).

TypeScript

Copy

Read more about the WalletProvider API and the ChainProvider API.

Activate your providerarrow-up-right

Activating the provider is required before it can be used to interact with the user's wallet. When activation is triggered, a popup is triggered for the user to allow your site access to their wallet. The user may choose a subset of their wallets to share if they have multiple. Activation can be achieved with one of the following methods.

Using dag_requestAccounts or eth_requestAccounts RPC methodsarrow-up-right

Calling dag_requestAccounts or eth_requestAccounts RPC methods, depending on the provider being used, will send an activation request for the user to accept. If the user accepts the request, the RPC method will return available accounts for the provider; if not, it will throw an error.

TypeScript

Copy

Read more about the different RPC methods available both for Constellationarrow-up-right and Ethereumarrow-up-right.

Activate method (deprecated)arrow-up-right

Warning

This method of activation has been deprecated in favor of the EIP-1102arrow-up-right specification, in both Constellation and Ethereum providers.

You can send an activation request to the user using the provider's activate()arrow-up-right method. Once the user accepts the request you'll be able to use the provider's RPC interface and methods for the selected chain.

TypeScript

Copy

Read more about the different RPC methods available both for Constellationarrow-up-right and Ethereumarrow-up-right.

Scope of the activationarrow-up-right

Activations are issued for the page originarrow-up-right and cover all chains available (currently Constellation and Ethereum) and on all providers given. If you have been granted activation in the past the user will not be asked to grant it again. If the user is logged out, they will be prompted to log in again.

ChainProvider identityarrow-up-right

All chain providers are instantiated once per page, and per chain with the following setup:

TypeScript

Copy

Two chain providers from the same network and page will share the same underlying reference:

  • Object.is(constellationProviderA, constellationProviderB) will be true.

  • Object.is(ethereumProviderA, ethereumProviderB) will be true.

  • Object.is(constellationProviderA, ethereumProviderB) will be false.

  • Object.is(constellationProviderB, ethereumProviderA) will be false.

Last updated

Was this helpful?