Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream useful helpers into @cosmjs/cli #385

Open
ethanfrey opened this issue Aug 14, 2020 · 7 comments
Open

Upstream useful helpers into @cosmjs/cli #385

ethanfrey opened this issue Aug 14, 2020 · 7 comments

Comments

@ethanfrey
Copy link
Contributor

In CosmWasm/cw-plus#46 I went to make the easiest intro to using the cw20-base contract via @cosmjs/cli. However, the setup code we have by default wasn't the simplest, so I refactored this along the way.

In particular, please look at this code section: https://github.com/CosmWasm/cosmwasm-plus/blob/master/contracts/cw20-base/helpers.ts#L19-L134

It allows us to simply const client = await useOptions(coralnetOptions).setup(password); and create or recover a password-encrypted key, configured with all chain-specific options. We can provide different options, like gaiaFlexOptions for easy drop-in. I also worked to limit the number of top-level exports to avoid name-space pollution.

However, I would rather not copy this code in each contract we support with helpers and wanted to upstream it to @cosmjs/cli. I was thinking to keep the actual concrete options in the contract helpers for now, until we figure out how to do mix ins (options from testnets dir, cw20-base bindings here, cw1-subkeys bindings here...).

@webmaster128
Copy link
Member

#399 and #404 should reduce the burden for the caller a lot. Now you only need to set the gas price once and all fees are auto-calculated. Gas limits only need to be set on-demand when the defaults are now suitable.

@webmaster128
Copy link
Member

Here is a list of simplifications to the code that can happen with CosmJS 0.32


One thing we could add is a faucet client, like https://github.com/iov-one/iov-core/blob/master/packages/iov-faucets/src/iovfaucet.ts, which would internalize networking and turn

const hitFaucet = async (
    faucetUrl: string,
    address: string,
    ticker: string
  ): Promise<void> => {
    await axios.post(faucetUrl, { ticker, address });
  }

 // ...

    // ensure we have some tokens
    if (options.faucetUrl) {
      const account = await client.getAccount();
      if (!account) {
        console.log(`Getting ${options.feeToken} from faucet`);
        await hitFaucet(options.faucetUrl, client.senderAddress, options.faucetToken);
      }  
    }

into

    // ensure we have some tokens
    if (options.faucetUrl) {
      const account = await client.getAccount();
      if (!account) {
        console.log(`Getting ${options.feeToken} from faucet`);
        await new FaucetClient(options.faucetUrl).credit(client.senderAddress, options.feeToken);
      }  
    }

@ethanfrey
Copy link
Contributor Author

Those all look like nice UX improvements, and would simplify most of useOptions from the cw20 helpers.ts file. FaucetClient or just adding hitFaucet function to cosmjs would also be nice.

I would also be interested in adding some of the interfaces to the cwXyz standard. Maybe just the execute ones for eg. cw20, cw3, cw721. We will need to have the cw3 (and likely the TBD cw4) interface to use multisigs for example. I am fine to skip the upload code and instantiate code parts from @cosmjs (which are implementation detail, not in the specs), and just support the handle and query messages as part of the specs and consistent among all contracts that implement those.

@webmaster128
Copy link
Member

FaucetClient or just adding hitFaucet function to cosmjs would also be nice.

The problem with hitFaucet is it is too simple for a general purpose library. The faucet as other calls, like /status and of we go into the faucet client business, we would want to support those as well (or at least be prepared to do so).

I would also be interested in adding some of the interfaces to the cwXyz standard. Maybe just the execute ones for eg. cw20, cw3, cw721. We will need to have the cw3 (and likely the TBD cw4) interface to use multisigs for example. I am fine to skip the upload code and instantiate code parts from @cosmjs (which are implementation detail, not in the specs), and just support the handle and query messages as part of the specs and consistent among all contracts that implement those.

Yeah, those can be in @cosmjs/cosmwasm or @cosmjs/cw-interfaces, depending from where we need them. We'll figure it out when building the multisig client functionality.

@ethanfrey
Copy link
Contributor Author

The problem with hitFaucet is it is too simple for a general purpose library. The faucet as other calls, like /status and of we go into the faucet client business, we would want to support those as well (or at least be prepared to do so).

Fair enough. "faucet client business" sounds nice

Yeah, those can be in @cosmjs/cosmwasm or @cosmjs/cw-interfaces, depending from where we need them. We'll figure it out when building the multisig client functionality.

Cool. They can easily be added in a 0.23.x patch release as well, just wanted to have them on your radar.

@webmaster128
Copy link
Member

Starting with 0.23.1, you can use a FaucetClient in the CLI (see #470)

@webmaster128
Copy link
Member

0.23.1 was just released, including the FaucetClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants