Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Readme Touchup #83

Merged
merged 13 commits into from
Feb 7, 2022
160 changes: 61 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# `lens`

**Lens provides a cmd line tool to interact with any cosmos chain supporting the core [Cosmos-SDK modules](https://github.com/cosmos/cosmos-sdk/tree/master/x).**
boojamya marked this conversation as resolved.
Show resolved Hide resolved

**Lens is meant to be imported and used in other repos and projects to eaily navigate and interact with the Cosmos Hub.**
boojamya marked this conversation as resolved.
Show resolved Hide resolved

---

`lens` is your lens to view the Cosmos :atom:. `lens` packs all the best practices in golang cosmos client development into one place and provides a simple and easy to use APIs provided by standard Cosmos chains. The `cmd` package implements the `lens` command line tool while the `client` package contains all the building blocks to build your own, complex, feature rich, Cosmos client in go.

Intended use cases:
Expand All @@ -11,23 +17,20 @@ Intended use cases:

This is the start of ideas around how to implement the cosmos client libraries in a seperate repo.

## Tutorial

### CMD Line

Lens provides a cmd line tool to interact with any cosmos chain supporting the core [Cosmos-SDK modules](https://github.com/cosmos/cosmos-sdk/tree/master/x).

#### Install

```
## **--INSTALL--**
---
```bash
git clone https://github.com/strangelove-ventures/lens.git

cd lens

make install
```

After running the above commands, when running `lens` you should see
Now run:
```bash
lens
```
You should see:

```
❯ lens
Expand All @@ -53,113 +56,72 @@ Flags:
Use "lens [command] --help" for more information about a command.
```

#### Chains
## **--CONFIG--**
---
The config file tells lens how to interact with blockchains. This is where information such as grpc address's and chain-ids are held.
boojamya marked this conversation as resolved.
Show resolved Hide resolved

Lens comes with two defaulted chains, Cosmos Hub and Osmosis. Located at `~/.lens/config.toml`
**Config File Location:** `~/.lens/config.yaml`

```
default_chain: osmosis
chains:
cosmoshub:
key: default
chain-id: cosmoshub-4
rpc-addr: https://cosmoshub-4.technofractal.com:443
grpc-addr: https://gprc.cosmoshub-4.technofractal.com:443
account-prefix: cosmos
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01uatom
key-directory: /Users/lenscrafters/.lens/keys
debug: false
timeout: 20s
output-format: json
sign-mode: direct
osmosis:
key: default
chain-id: osmosis-1
rpc-addr: https://osmosis-1.technofractal.com:443
grpc-addr: https://gprc.osmosis-1.technofractal.com:443
account-prefix: osmo
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01uosmo
key-directory: /Users/lenscrafters/.lens/keys
debug: false
timeout: 20s
output-format: json
sign-mode: direct
```
> NOTE: The config file is not created at install, it is created the first time lens needs to query your config. Just to get it created, you can run something like:
>```
>lens chains show-default
>```
boojamya marked this conversation as resolved.
Show resolved Hide resolved

To add more chains to your config, run:
### **CHAINS**
Lens comes with two defaulted chains. Cosmos Hub and Osmosis.
boojamya marked this conversation as resolved.
Show resolved Hide resolved

To interact with other chains, you need to add them to your config, run:
boojamya marked this conversation as resolved.
Show resolved Hide resolved

```
lens chains add <chain_name>
#Example:
lens chains add juno
```

To view all possible chain names, run:
```
lens chains registry-list
```
> NOTE: These two commands check the chain registry located [here](https://github.com/cosmos/chain-registry), for the requested chain.

When running a command, it will run the command for the defaulted chain.

This command checks the chain registry located [here](https://github.com/cosmos/chain-registry), for the requested chain. The chain name references the directory name in the chain registry. After running `lens chains add juno` your `config.toml` should look like
To view your default chain, run:

```
default_chain: osmosis
chains:
cosmoshub:
key: default
chain-id: cosmoshub-4
rpc-addr: https://cosmoshub-4.technofractal.com:443
grpc-addr: https://gprc.cosmoshub-4.technofractal.com:443
account-prefix: cosmos
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01uatom
key-directory: /Users/lenscrafters/.lens/keys
debug: false
timeout: 20s
output-format: json
sign-mode: direct
juno:
key: default
chain-id: juno-1
rpc-addr: https://rpc-juno.itastakers.com:443
grpc-addr: ""
account-prefix: juno
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01ujuno
key-directory: /Users/lenscrafters/.lens/keys
debug: false
timeout: 20s
output-format: json
sign-mode: direct
osmosis:
key: default
chain-id: osmosis-1
rpc-addr: https://osmosis-1.technofractal.com:443
grpc-addr: https://gprc.osmosis-1.technofractal.com:443
account-prefix: osmo
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01uosmo
key-directory: /Users/lenscrafters/.lens/keys
debug: false
timeout: 20s
output-format: json
sign-mode: direct
lens chains show-default
```

When running a command, it will run the command for the defaulted chain. The defaulted chain can be found at the top of `~/.lens/config.toml` or by running `lens`.

To change your default, run:

```
lens chains set-default <chain_name>
```

#### Keys
### **Keys**
Lens uses the keyring from the Cosmos-sdk. There is more information about it keyring [here](https://github.com/cosmos/cosmos-sdk/blob/master/crypto/keyring/doc.go).
boojamya marked this conversation as resolved.
Show resolved Hide resolved

Lens uses the keyring from the Cosmos-sdk. There is more information about it keyring [here](https://github.com/cosmos/cosmos-sdk/blob/master/crypto/keyring/doc.go). To add a key to lens run:
To add a key to lens you have two options:

```
lens keys restore <key_name>
```
* `lens keys add` - This will add a key to you default chain and name it "default". You can optionally add a name as an argument.
* `lens keys restore <name>` - This will restore a key to your default chain. Replace '\<name\>' with a key name. This command will THEN ask for your mnemonic which is needed to restore and use it to boradcast transactions.
boojamya marked this conversation as resolved.
Show resolved Hide resolved

>❗️ NOTE: IF you name your key anything other than "default", you will need to manually change the `key:` value in your config to link key with chain.
>```bash
>default_chain: cosmoshub
>chains:
> cosmoshub:
> key: default #CHANGE THIS NAME
> chain-id: cosmoshub-4
> rpc-addr: https://cosmoshub-4.technofractal.com:443
> ...
>```

After adding or restoring a key, it should appear in your list by running: `lens keys list`, by default it will show the Cosmos Hub address.
boojamya marked this conversation as resolved.
Show resolved Hide resolved

To see the key encoded for use on other chains run `lens keys enumerate <key_name>`.


## --QUICKSTART EXAMPLES--
---

After restoring a key, it should appear in your list by running: `lens keys list`, by default it will show the Cosmos Hub address. To see the key encoded for use on other chains run `lens keys enumerate <key_name>`.
11 changes: 6 additions & 5 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package cmd
import (
"encoding/json"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"log"
"sort"
"strings"

"golang.org/x/crypto/ssh/terminal"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -47,12 +48,12 @@ func keysAddCmd() *cobra.Command {
Use: "add [name]",
Aliases: []string{"a"},
Short: "adds a key to the keychain associated with a particular chain",
Long: "if no name is passed, name in config is used",
Long: "if no name is passed, 'default' is used",
Args: cobra.RangeArgs(0, 1),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s keys add ibc-0
$ %s keys add ibc-1 key2
$ %s k a ibc-2 testkey`, appName, appName, appName)),
$ %s keys add
$ %s keys add test_key
$ %s k a osmo_key --chain osmois`, appName, appName, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
cl := config.GetDefaultClient()
var keyName string
Expand Down