npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@csli/repl

v0.1.4

Published

a REPL connecting to Cosmos blockchains using the @cosmjs suite of libraries

Downloads

15

Readme

@csli/repl — a REPL using @cosmjs

First and foremost, shout-out to Simon Warta for making the @cosmjs/cli, which is where most of this code is taken from. It feels like the intentions of this project will likely depart far enough from the original that it makes sense to have its own package.

Installation and first run

The cslir executable is available via npm. We recommend local installations to your demo project.

locally with yarn

$ yarn add @csli/repl --dev
$ ./node_modules/./bin/cslir

locally with npm

$ npm install @csli/repl --save-dev
$ ./node_modules/./bin/cslir

globally with yarn

$ yarn global add @csli/repl
$ cslir

globally with npm

$ npm install -g @csli/repl
$ cslir

Getting started

  1. Install @csli/repl and run cslir as shown above
  2. Start a local wasmd blockchain
  3. Start with ./bin/cslir --init examples/local_faucet.ts
  4. Play around as in the following example code
// Get account information
const account = await client.getAccount(faucetAddress);

// Craft a send transaction
const emptyAddress = Bech32.encode("cosmos", Random.getBytes(20));
const memo = "My very first tx!";
const msgSend = {
  fromAddress: faucetAddress,
  toAddress: emptyAddress,
  amount: coins(1234, "ucosm"),
};

const msgAny = {
  typeUrl: "/cosmos.bank.v1beta1.MsgSend",
  value: msgSend,
};

// Broadcast and sign the transaction
const broadcastResult = await client.signAndBroadcast(
  faucetAddress,
  [msgAny],
  defaultFee,
  memo,
);

Extended helpers

The above code shows you the use of the API and various objects and is a great way to learn how to embed CosmJS into your project. However, if you just want a cli to perform some quick queries on a chain, you can use an extended set of helpers:

Start with ./bin/cslir --init examples/helpers.ts

(This points to the Demonet at https://lcd.demo-08.cosmwasm.com for ease of use. Other networks, look below)

Setup Account:

// you can hand-copy a mnemonic here, but this is easiest for reuse between sessions
// it creates a random one first time, then reads it in the future
const mnemonic = loadOrCreateMnemonic("foo.key");
const { address, client } = await connect(mnemonic, {});
address;

client.getAccount();
// if empty - this only works with CosmWasm
hitFaucet(defaultFaucetUrl, address, "COSM");
client.getAccount();

View contracts:

// show all code and contracts
client.getCodes();

// query the first contract for first code
const contracts = await client.getContracts(1);
contracts;
const info = await client.getContract(contracts[0].address);
info;
info.initMsg;

// see your balance here
client.queryContractSmart(addr, { balance: { address } });

Instantiate and use ERC20 contract:

// no money? no problem.
// let's make our own s**coin - replace "FOO" with something else to avoid duplicates
const initMsg = {
  name: "Foo Coin",
  symbol: "FOO",
  decimals: 2,
  initial_balances: [{ address, amount: "123456789" }],
};
const foo = await client.instantiate(1, initMsg, "FOO");
foo;
foo.logs[0].events[0];
const fooAddr = foo.contractAddress;

// we can also find this another way...
const fooAddr2 = await client
  .getContracts(1)
  .then(
    (contracts) =>
      contracts.filter((x) => x.label == "FOO").map((x) => x.address)[0],
  )[(fooAddr, fooAddr2)];

// now we have some cash
client.queryContractSmart(fooAddr, { balance: { address } });

const rcpt = await randomAddress("cosmos");
rcpt;
client.queryContractSmart(fooAddr, { balance: { address: rcpt } });

const execMsg = { transfer: { recipient: rcpt, amount: "808" } };
const exec = await client.execute(fooAddr, execMsg);
exec;
exec.logs[0].events[0];
client.queryContractSmart(fooAddr, { balance: { address: rcpt } });

Or just send tokens:

client.getAccount(rcpt);

const sent = await client.sendTokens(rcpt, [
  { amount: "1234", denom: "ucosm" },
]);
sent;
foo.logs[0].events[0];

Use Custom Network

All the network info can be configured inside the last argument to connect. To see how to connect to the Regen Testnet, try this. (Note you need to use .editor in the repl to allow multi-line commands. Alternative is to place entire regenOptions on one line.

Run ./bin/cslir --init examples/helpers.ts

.editor
const regenOptions = {
  httpUrl: "https://regen-lcd.vitwit.com/",
  networkId: "kontraua",
  feeToken: "utree",
  gasPrice: 0.025,
  bech32prefix: "xrn:",
}
^D

const mnemonic = loadOrCreateMnemonic("regen.key");
const {address, client} = await connect(mnemonic, regenOptions);
address

// check some random genesis account
client.getAccount("xrn:1pdfr7xuckj6lhdphdde6peres9ufwgpsv87mag")

// your own account is undefined unless you did this before
client.getAccount()

Hit the faucet with your address (in browser): https://regen.vitwit.com/faucet then continue in node

// should have tokens now
client.getAccount();

At this point you can continue all the other behaviors from above, looking at codes, etc. Do note that the ERC contract is code 5 on this network (instead of 1 above).

Importing keys from wasmcli

If you are using the go commands and have tokens there, you may want to reuse the same account. (If you don't know what this is, just skip this section). You can reuse the mnemonic between the Go tooling and the Node.js tooling, but this violates all security protocols - only use this for testnets. In the future we will offer proper encrypted key management for CosmJS.

(You can replace wasmcli with xrncli and use regenOptions if you wish to use that testnet)

Create a new key - note mnemonic and address

$ wasmcli keys add demo2

- name: demo2
  type: local
  address: cosmos1d4ut3z9c0kplgz5ma9t6ee637tagjqfyu4sxyl
  pubkey: cosmospub1addwnpepqtagg2smk2zvj77xaslej2wevwz7jft0q5hj5yuwvek3r6z0ufjtxnde4rq
  mnemonic: ""
  threshold: 0
  pubkeys: []


**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.

cousin nephew vintage label empty sunny cargo mushroom photo side clarify sleep solid entire deal tattoo vehicle record discover arrive sting staff salt uncle

Save mnemonic to a file:

echo "cousin nephew vintage label empty sunny cargo mushroom photo side clarify sleep solid entire deal tattoo vehicle record discover arrive sting staff salt uncle" > wasmcli.key

Load it up in CosmJS: ./bin/cslir --init examples/helpers.ts

const mnemonic = loadOrCreateMnemonic("wasmcli.key");
const { address, client } = await connect(mnemonic, regenOptions);

// this should match what you got on the cli - showing compatibility
address;

Once you have access to the same key as in the cli, you can use those tokens to play with contracts.

Diving into Contracts

Check out the mask documentation to view how to use some custom helpers to upload code and use non-trivial contracts with proper types.

License

This package is part of the CosmJS repository, licensed under the Apache License 2.0 (see NOTICE and LICENSE).