# 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 ([devtools](https://developer.chrome.com/docs/devtools/console/)).

### Detect Stargazer[​](https://docs.constellationnetwork.io/stargazer/Guide/providerActivation#detect-stargazer) <a href="#detect-stargazer" id="detect-stargazer"></a>

The Stargazer browser extension injects a [`WalletProvider`](https://docs.constellationnetwork.io/stargazer-wallet/api-reference/wallet-provider-api) instance under `window.stargazer` each time a page loads. You can check the existence of this property using the following snippet.

TypeScript

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

Copy

### Obtain a ChainProvider[​](https://docs.constellationnetwork.io/stargazer/Guide/providerActivation#obtain-a-chainprovider) <a href="#obtain-a-chainprovider" id="obtain-a-chainprovider"></a>

Once you've verified your app has access to a [`WalletProvider`](https://docs.constellationnetwork.io/stargazer-wallet/api-reference/wallet-provider-api) instance you can obtain a [`ChainProvider`](https://docs.constellationnetwork.io/stargazer-wallet/chain-provider-api) to interact with a network of your choice (Constellation or Ethereum).

TypeScript

```typescript
const provider = window.stargazer.getProvider("constellation");
```

Copy

*Read more about the* [*WalletProvider API*](https://docs.constellationnetwork.io/stargazer-wallet/api-reference/wallet-provider-api) *and the* [*ChainProvider API*](https://docs.constellationnetwork.io/stargazer-wallet/chain-provider-api)*.*

### Activate your provider[​](https://docs.constellationnetwork.io/stargazer/Guide/providerActivation#activate-your-provider) <a href="#activate-your-provider" id="activate-your-provider"></a>

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 methods[​](https://docs.constellationnetwork.io/stargazer/Guide/providerActivation#using-dag_requestaccounts-or-eth_requestaccounts-rpc-methods) <a href="#using-dag_requestaccounts-or-eth_requestaccounts-rpc-methods" id="using-dag_requestaccounts-or-eth_requestaccounts-rpc-methods"></a>

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

```typescript
await dagProvider.request({ method: "dag_requestAccounts", params: [] });
// ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX"] provider was activated

await ethProvider.request({ method: "eth_requestAccounts", params: [] });
// ["0xAab2C30c02016585EB36b7a0d5608Db787c1e44E"] provider was activated
```

Copy

*Read more about the different RPC methods available both for* [*Constellation*](https://docs.constellationnetwork.io/stargazer/APIReference/constellationRPCAPI/) *and* [*Ethereum*](https://docs.constellationnetwork.io/stargazer/APIReference/ethereumRPCAPI/)*.*

#### Activate method (deprecated)[​](https://docs.constellationnetwork.io/stargazer/Guide/providerActivation#activate-method-deprecated) <a href="#activate-method-deprecated" id="activate-method-deprecated"></a>

**Warning**

This method of activation has been deprecated in favor of the [EIP-1102](https://eips.ethereum.org/EIPS/eip-1102) specification, in both Constellation and Ethereum providers.

You can send an activation request to the user using the provider's [`activate()`](https://docs.constellationnetwork.io/stargazer/APIReference/chainProviderAPI/activate) 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

```typescript
const activated = await provider.activate("A Cool App Name");
```

Copy

*Read more about the different RPC methods available both for* [*Constellation*](https://docs.constellationnetwork.io/stargazer/APIReference/constellationRPCAPI/) *and* [*Ethereum*](https://docs.constellationnetwork.io/stargazer/APIReference/ethereumRPCAPI/)*.*

### Scope of the activation[​](https://docs.constellationnetwork.io/stargazer/Guide/providerActivation#scope-of-the-activation) <a href="#scope-of-the-activation" id="scope-of-the-activation"></a>

Activations are issued for the page [origin](https://datatracker.ietf.org/doc/html/rfc6454) 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 identity[​](https://docs.constellationnetwork.io/stargazer/Guide/providerActivation#chainprovider-identity) <a href="#chainprovider-identity" id="chainprovider-identity"></a>

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

TypeScript

```typescript
const constellationProviderA = window.stargazer.getProvider("constellation");
const constellationProviderB = window.stargazer.getProvider("constellation");

const ethereumProviderA = window.stargazer.getProvider("ethereum");
const ethereumProviderB = window.stargazer.getProvider("ethereum");
```

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.
