Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
leapsamvel committed Aug 14, 2023
1 parent c9e9315 commit 9aa804a
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions packages/cosmos-snap-provider/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
# cosmos-snap-provider

## Usage
Cosmos Snap provider has been created for directly using the [Leap Cosmos Snap](https://www.npmjs.com/package/@leapwallet/metamask-cosmos-snap) with cosmos js client.

## Methods

### getSnap
This method helps to identify whether leap cosmos snap is installed or not in the metamask instance installed in user browser


```typescript
import { getSnap, connectSnap, getKey } from '@leapwallet/cosmos-snap-provider'
const snapInstalled = await getSnap() // return true if already installed
```

async function connect(){
//check if snap is installed
const snapInstalled = await getSnap()
if(!snapInstalled) {
// Install snap if not already installed
connectSnap()
}

}
### connectSnap
Connect snap lets you connect to leap cosmos snap if installed else it will trigger the installation and connects to the snap.

```typescript
import { getSnap, connectSnap, getKey } from '@leapwallet/cosmos-snap-provider'

async function getAccount(){
await connect()
const chainId = 'cosmoshub-4'
const key = await getKey(chainId)
return key
// check if snap is installed
const snapInstalled = await getSnap()
if(!snapInstalled) {
// Install snap if not already installed
connectSnap()
}
```

### getKey
GetKey helps in getting the chain address for the particular chainId. This should be called once the snap is been connected with the dapp.

```typescript
const key = await getKey(chainId)
```

## Usage with cosmjs
### cosmjsOfflineSigner

The best way to use the provider if you already using the cosmjs libraries for signing is by using it as an offline signer with existing cosmwasm clients.
Make sure the dapp connected to snap before using it as an offline signer.

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


import { cosmjsOfflineSigner } from '@leapwallet/cosmos-snap-provider'



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

```

0 comments on commit 9aa804a

Please sign in to comment.