# Add Leap to a new dapp

Assuming you have built out your own Connect to Leap UI component, the handling process could be as follows :&#x20;

* If `window.leap` is available, you can access Leap APIs using the `window.leap` object that is injected into the web app on page load
* If `window.leap` is not available, use our dynamic link instead which will redirect users to an Install page on the Desktop browser and to the dapp page on Leap mobile app on the mobile browser

If the chain involved is not natively supported on Leap, then you can use the [Suggest Chain](/cosmos/for-dapps-connect-to-leap/suggest-chain-add-leap-to-a-non-native-chain.md) implementation

### Basic Usage

* Check if the leap provider is available

```javascript

if(!window.leap){
  console.log("leap wallet not installed")
}else{
  // initialise the app
}
```

* Get users account for a chain using chain id

```javascript

async function getKey(){
  const key = await window.leap.getKey('cosmoshub-4)
  console.log("cosmoshub address", key.bech32Address)
}

```

* Add a listener to track account changes within the wallet

```
window.addEventListener('leap_keystorechange', getKey)
```

### CosmJS example

Below is an example implementation that you can follow&#x20;

```javascript
import { SigningStargateClient } from '@cosmjs/cosmwasm-stargate'
import { GasPrice } from '@cosmjs/stargate'

await window.leap.enable(chainId);

const offlineSigner = window.leap.getOfflineSignerAuto(chainId);
const accounts = await offlineSigner.getAccounts();
const rpcUrl = "" // Replace with a RPC URL for the given chainId
const stargateClient = await SigningStargateClient.connectWithSigner(
  rpcUrl,
  offlineSigner,
  {
    gasPrice: GasPrice.fromString("0.0025ujuno"),
  }
)
```

Refer to [Leap Assets](/cosmos/resources/leap-assets.md) for the wallet name, logo, and redirection link in case Leap Wallet is not installed


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.leapwallet.io/cosmos/for-dapps-connect-to-leap/add-leap-to-a-new-dapp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
