# API Reference

### Enable connection:

The `window.leap.enable(chainIds)` method redirects to the extension login page if it is locked. If the user hasn't permitted the webpage, it will ask the user to enable the webpage to access Leap.

```jsx
window.leap.enable(chainId: string | Array<string>)
// you can pass a list of chainIds to get approval for multiple chains in one request
window.leap.enable(['chainId1', 'chainId2'])
```

Note: In a case where multiple wallets are imported, users can select the wallet/wallets that are supposed to be enabled.

### Get Key:

If the webpage has permission and Leap wallet is unlocked, this function will return the address and public key in the following format:

```typescript
interface Key {
  name: string;
  algo: string;
  pubKey: Uint8Array;
  address: Uint8Array;
  bech32Address: string;
  isNanoLedger: boolean;
}

window.leap.getKey(chainId: string): Promise<Key>
```

### Sign Amino:

Like `signAmino` method of CosmJS OfflineDirectSigner, however, Leap's `signAmino` function takes the chain-id as a required parameter. Signs Amino-encoded StdSignDoc.

```typescript
interface SignOptions {
 // If set to true the wallet will not override fees specified in the signDoc.
  preferNoSetFee: boolean
}  

signAmino(chainId: string, signer: string, signDoc: StdSignDoc, signOptions?: SignOptions): Promise<AminoSignResponse>
```

### **Sign Direct / Protobuf:**

Like `signDirect` method of CosmJS OfflineDirectSigner, however, Leap's `signDirect` function takes the chain-id as a required parameter. Signs Proto-encoded StdSignDoc.

```typescript
interface SignDoc {
  bodyBytes?: Uint8Array | null;
  authInfoBytes?: Uint8Array | null;
  chainId?: string | null;
  accountNumber?: Long | null;
}

interface SignOptions {
 // If set to true the wallet will not override fees specified in the signDoc.
  preferNoSetFee: boolean
}  

signDirect(chainId:string, signer:string, signDoc: SignDoc, signOptions?: SignOptions): Promise<DirectSignResponse>
```

### Request Signature for Arbitrary Message:  <a href="#request-signature-for-arbitrary-message" id="request-signature-for-arbitrary-message"></a>

```typescript
signArbitrary(
    chainId: string,
    signerAddress: string,
    data: string | Uint8Array
): Promise<StdSignature>;

await window.leap.signArbitrary(chainId, signerAddress, 'hello')
```

### Delegate Transaction broadcasting:

Webpages can use this function to delegate the broadcasting of the transaction to LCD endpoints configured in the leap wallet. If the broadcast is successful, this method will return the transaction hash. Otherwise, it will throw an error.

```typescript
sendTx(
    chainId: string,
    tx: Uint8Array,
    mode: BroadcastMode
): Promise<Uint8Array>;
```

### CosmJS example

Leap’s API is similar to Keplr's to keep the integration of leap for the dApp as easy as possible.

```javascript

import { GasPrice, SigningStargateClient } from '@cosmjs/stargate'

await window.leap.enable(chainId);

const signOptions = {
  // set this to true to prevent leap from overriding the fees.
  preferNoFeeSet: false
}

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

### Method to add a CW20 token

```javascript
await window.leap.suggestCW20Token(chainId, contractAddress) 
```

### Method to check wallet connection

```javascript
await window.leap.isConnected(chainId) // returns boolean 
```

### Disconnect from Dapp

```javascript
await window.leap.disconnect(chainId) // returns boolean 
```

### Get Supported Chains

```javascript
const supportedChains = await window.leap.getSupportedChains()
```
