Skip to content

Commit

Permalink
updated-cw-docs (#3659)
Browse files Browse the repository at this point in the history
#3642 with addressed comments

- [x] PR title is my best effort to provide summary of changes and has
clear text to be part of release notes
- [x] I marked PR by `misc` label if it should not be in release notes
- [ ] I have linked Zenhub/Github or any other reference item if one
exists
- [ ] I was clear on what type of deployment required to release my
changes (node, runtime, contract, indexer, on chain operation, frontend,
infrastructure) if any in PR title or description
- [ ] I waited and did best effort for `pr-workflow-check /
draft-release-check` to finish with success(green check mark) with my
changes
- [ ] I have added at least one reviewer in reviewers list
- [ ] I tagged(@) or used other form of notification of one person who I
think can handle best review of this PR
  • Loading branch information
JafarAz authored Jun 1, 2023
1 parent c187eef commit d2c1ade
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 39 deletions.
87 changes: 61 additions & 26 deletions docs/docs/developer-guides/cosmwasm-cli.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
# Composable CosmWasm CLI

Composable Cosmwasm CLI is a CLI tool to quickly get started with the XCVM ecosystem and interact with a chain that runs `pallet-cosmwasm`. In this guide, we will show you how to run the CLI on Picasso rococo.
Composable Cosmwasm CLI is a CLI tool to quickly get started with the XCVM ecosystem and interact with a chain that runs `pallet-cosmwasm`. In this guide, we will show you how to run the CLI on a local Picasso network and Picasso Rococo.

## Installing `ccw`
:::info
Picasso Rococo is a testnet (test network) for [Picasso](../parachains/picasso-parachain-overview.md). It allows developers to experiment, test runtime module deployment, and refine their applications to ensure the stability and compatibility of new features before deploying on Picasso mainnet by interacting with the [Rococo Relay Chain](https://polkadot.network/blog/rococo-revamp-becoming-a-community-parachain-testbed/).
:::

There are two methods to installing the ccw-vm:
## Setting up the development environemnt

1. At first, clone the [Composable moonorepo](https://github.com/ComposableFi/composable):
The process of setting up a development environment for deploying CosmWasm contracts, both a local Picasso netork and on Picasso Rococo, follows the same procedure. There is a distinction in the RPC endpoint mentioned in the CLI commands to upload, instantiate and execute contracts. To interact with a local Picasso network, you will utilize `ws://127.0.0.1:9988` whereas to deploy on Picasso Rococo, you will employ `wss://picasso-rococo-rpc-lb.composablenodes.tech:443`. Additionally, please note that the "-n alice" sudo key will be substituted with your seed phrase when entering the commands.

```
git clone https://github.com/ComposableFi/composable
```
Nix is a requirement to set up and start a local development environment with Composable's code. We recommend using the [Zero-to-Nix installer](https://zero-to-nix.com/start/install) to install Nix. Refer to our [docs](../nix.md) for more information.

### Installing `ccw`

Then run the following command to install the ccw binary:
There are two methods to installing the `ccw-vm`:

1. Install the `ccw` crate from the Composable monorepo:

```
cargo install --path ./composable/code/parachain/frame/cosmwasm/cli
cargo install --git https://github.com/ComposableFi/composable ./composable/code/parachain/frame/cosmwasm/cli
```

2. An alternative method to run the ccw-vm is by running the following command which requires Nix. Nix is required to start the development environment to deploy contracts on Picasso rococo:
2. An alternative method to run the `ccw-vm` is by running the following command using Nix.:

```
nix run composable#ccw
nix run profile install composable#ccw
```
### Setting up the DevNet

## Installing `nix`
To run a local network with Alice sudo key and start the development environment, run the following commands:

We are using Nix to set up and start our local development environment. So check out our
[Nix installation page](https://docs.composable.finance/nix/install) to install Nix.
```
nix develop composable
```

Then start the development environment by running:
:::info Nix flags
If this is your first time using Nix and running on a non-NixOS, ensure you include the correct flags after your Nix commands.
:::

```
nix run composable#devnet-picasso
Expand All @@ -40,6 +48,22 @@ This will take time at first but since it is cached, it will be almost instant a
```
nix run "github:ComposableFi/composable/d2845fc731bc3ee418a17cf528336d50f4b39924#devnet-picasso"
```

### Setting up the environment to deploy on a local network of Picasso

Once your node is set up on local from the previous step, open the Polkadot-Js explorer to view activity changes on your local network by heading to the development section with the custom endpoint linked [here](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9988#/explorer). If Polkadot-JS fails to load your local network after running the node, it is possible that there was an error during the build process, resulting in the failure to load it correctly.

### Setting up the environment to deploy on Picasso Rococo

Once you have completed the setup of your development environment, you can proceed to the [PolkadotJS explorer](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fpicasso-rococo-rpc-lb.composablenodes.tech#/explorer) dedicated to Picasso Rococo. This explorer allows you to monitor real-time events and also interact with `ccw` without the need to interact with the CLI.

To deploy contracts on Picasso Rococo, you will need PICA tokens for testing. To assist with this, we have established a [faucet](https://matrix.to/#/#picasso-rococo-faucet:matrix.org) on the Matrix platform. It enables developers to receive PICA tokens specifically for the Picasso Rococo network. To retrieve your address, you can visit the [Accounts page](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fpicasso-rococo-rpc-lb.composablenodes.tech#/accounts) in PolkadotJS. For detailed instructions on creating a PolkadotJS wallet, please refer to [this guide](../user-guides/polkadotjs-extension-create-account.md) we have published. Additionally, make sure you have updated to the latest metadata and have enabled the 'Allow use on any chain' option within the PolkadotJS plugin.

A useful resource for interacting with PolkadotJS is their [developer documentation](https://polkadot.js.org/docs/).

## Interacting with the CLI

<!-- This section is omitted for now as it is not possible to do this until we update our version of cw.
## Create a CosmWasm project
You can create a base CosmWasm project that you can work on.
Expand All @@ -49,25 +73,36 @@ ccw new --name get-started --description "Get started with CosmWasm"
```
See [here](./cosmwasm/new-project.md) for more.
-->

## Upload a CosmWasm contract

For interacting with `pallet-cosmwasm`, `substrate` subcommand is used. To be able
to call your contracts, you need to upload them to the chain first. There are several
sources to upload your contracts:
### Upload a CosmWasm contract

### 1. Upload a local contract binary
For interacting with `cosmwasm`, the `substrate` subcommand is used. To be able
to call your contracts, you need to upload them to the chain first. The difference between running on a local devnet and on Picasso Rococo is to replace '-n Alice' with your seed phrase in the commands and the RPC endpoints, an example is provided below during the upload of a local contract binary.

There are several sources to upload your contracts:

#### 1. Upload a local contract binary

You need to specify the file path and the signer to be able to upload a contract
from the file path. Extrinsics must be called by a signed entity in `pallet-cosmwasm`.
For now, the examples will use development accounts for signing extrinsics, but
we will explain it further later.

```
cd path/to/file
```

```sh
# On Picasso local
ccw substrate -c ws://127.0.0.1:9988 -n alice tx upload --file-path .path/to/file
```

```sh
ccw -n alice upload -f /path/to/file.wasm
# On Picasso Rococo
ccw substrate -c wss://picasso-rococo-rpc-lb.composablenodes.tech:443 --seed "<your SEED phrase>" tx upload --file-path .path/to/file
```

### 2. Upload a contract from a running chain
#### 2. Upload a contract from a running chain

If a Cosmos chain provides an RPC endpoint, you can use it to load the contracts
to `ccw`. All you need to know is the RPC endpoint to fetch the
Expand All @@ -84,7 +119,7 @@ Fetch using the code ID:
ccw substrate -n alice tx upload --cosmos-rpc https://juno-api.polkachu.com --code-id 1
```

### 3. Upload a contract from a server
#### 3. Upload a contract from a server

One common thing is to go to a contract's release page and download the contract
binary from there. You don't have to do that with `ccw`.
Expand All @@ -94,6 +129,6 @@ binary from there. You don't have to do that with `ccw`.
ccw substrate -n alice tx upload --url https://github.com/CosmWasm/cw-plus/releases/download/v1.0.1/cw20_base.wasm
```

## Interact with a contract
## Interact with contracts

For examples of interacting with the contract, go to the [walkthrough](./cosmwasm/walkthrough.md).
3 changes: 3 additions & 0 deletions docs/docs/developer-guides/cosmwasm/cw-cli.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 51 additions & 12 deletions docs/docs/developer-guides/cosmwasm/walkthrough.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Walkthrough: cw20_base

In this walkthrough, we will upload and interact with `cw20_base` contract on Picasso rococo. We will:
* Fetch the contract binary from a running Cosmos chain and upload it to our chain.
* Instantiate the contract.
* Execute a transfer.
In this walkthrough, we will upload and interact with a `cw20_base` contract on a local Picasso network by:

* Fetching the contract binary from a running Cosmos chain and upload it to our chain.
* Instantiating the contract.
* Executing a transfer.

:::note
Ensure that you have followed the steps to setup the guide to install clone the `ccw` repository and install nix as outlined in the [first section](https://docs.composable.finance/developer-guides/cosmwasm-cli).
Ensure that you have followed the guide to setup your development environment as outlined in the [first section](https://docs.composable.finance/developer-guides/cosmwasm-cli).
:::

## Running `pallet-cosmwasm` on Picasso rococo
## Running `pallet-cosmwasm` on Picasso locally

**When running Picasso Rococo on a local development network versus on the Picasso Rococo mainnet, the only difference is that you need to replace '-n Alice' with your seed phrase in the commands and change the RPC endpoints. It is also required to add your port after the Rococo RPC endpoint, e.g. `wss://picasso-rococo-rpc-lb.composablenodes.tech:<insert port>`.**

**We have set up a faucet on Matrix for Picasso Rococo, allowing anyone to receive PICA tokens on rococo. Join [here](https://matrix.to/#/#picasso-rococo-faucet:matrix.org).**
### Uploading the contract

Let's say that we want to upload the `v1.0.1` release of `cw20_base`. We can directly use the download link from the [release page](https://github.com/CosmWasm/cw-plus/releases).

**Replace '-n Alice' with your public key in the commands.**

```sh
ccw substrate -c wss://picasso-rococo-unrpc-lb.composablenodes.tech/ -n alice tx upload --url https://github.com/CosmWasm/cw-plus/releases/download/v1.0.1/cw20_base.wasm
ccw substrate -c ws://127.0.0.1:9988 -n alice tx upload --url https://github.com/CosmWasm/cw-plus/releases/download/v1.0.1/cw20_base.wasm
```

Output:
Expand Down Expand Up @@ -68,7 +68,7 @@ make use of SS58 representations in the contracts as well, but for now, this is

So the command will be:
```sh
ccw substrate -c wss://picasso-rococo-unrpc-lb.composablenodes.tech/ -n alice \
ccw substrate -c ws://127.0.0.1:9988 -n alice \
tx instantiate \
-c 1 \
-s random-salt \
Expand Down Expand Up @@ -102,7 +102,7 @@ generation that we use is based on the instantiate parameters that we provide, n
address, use that address to execute the contract.

```sh
ccw substrate -c wss://picasso-rococo-unrpc-lb.composablenodes.tech/ -n bob \
ccw substrate -c ws://127.0.0.1:9988 -n bob \
tx execute \
-c 5EszMeNDPmy4orcLEHRLiJawAt5xAvfK5VH7REV8bpB1jtjX \
-g 10000000000 \
Expand Down Expand Up @@ -150,3 +150,42 @@ ccw substrate -c http://127.0.0.1:32200 \
-g 100000000 \
-q '{"balance":{"address":"0xd64439add16b49b6b68ac74e1b28a73a8491501ab7e0e829716f580947a4bd7e"}}'
```

## Running `pallet-cosmwasm` on Picasso Rococo

This is a specific example guide to upload, initialize and execute cw20 contracts on Picasso Rococo. The previous walkthough can also be applied to Picasso Rococo too, however, we have added another example specific to Rococo.


```sh
# Download the contract
curl --location https://github.com/CosmWasm/cw-plus/releases/download/v1.0.1/cw20_base.wasm > cw20_base.wasm`
```
```sh
# Upload the contract
cargo run substrate -c wss://picasso-rococo-rpc-lb.composablenodes.tech:443 --seed "<SEED>" tx upload --file-path ./cw20_base.wasm
```
```sh
# Instantiate the contract*
cargo run substrate -c wss://picasso-rococo-rpc-lb.composablenodes.tech:443 --seed "<SEED>" tx instantiate --code-id 1 --salt 0x1234 --label 0x4321 --gas 10000000000 --message '{ "decimals" : 18, "initial_balances": [], "name" : "SHIB", "symbol" : "SHIB", "mint": {"minter" : "5yNZjX24n2eg7W6EVamaTXNQbWCwchhThEaSWB7V3GRjtHeL"} }'
```
```sh
# Execute the contract
cargo run substrate -c wss://picasso-rococo-rpc-lb.composablenodes.tech:443 --seed "<SEED>" tx execute --contract "5CntM2NFn4Vkyu77tMDm5TRosKd9qskYpafh8L6Lz2FGP2rD" --gas 10000000000 --message '{ "mint" : { "amount" : "123456789", "recipient" : "5yNZjX24n2eg7W6EVamaTXNQbWCwchhThEaSWB7V3GRjtHeL" }}'
```
```sh
# Query the contract
cargo run substrate -c wss://picasso-rococo-rpc-lb.composablenodes.tech:443 rpc query --contract "5CntM2NFn4Vkyu77tMDm5TRosKd9qskYpafh8L6Lz2FGP2rD" --gas 10000000000 --query '{"balance": {"address": "5yNZjX24n2eg7W6EVamaTXNQbWCwchhThEaSWB7V3GRjtHeL"}}'
```

*After uploading the contract, please note that the "contract address" provided in the example of instantiating the contract may differ. It is possible that someone has already tested this smart contract on Picasso Rococo and uploaded it to the chain. As a result, you won't be able to upload the same contract again.
If you are running this contract locally, follow these steps:
1. Go to the 'Chain state' section within the 'Developer' tab.
2. Change the 'selected state query' to 'cosmwasm'.
3. Modify the dropdown option from 'codeHashTold' to 'contractToInfo'.
4. Toggle the 'include option' off.
5. This will retrieve the correct contract address. Refer to the image below as an example.
![polkadot_js1](./cw-cli.png)
Please ensure you follow these instructions to obtain the accurate contract address when running the contract locally.
1 change: 0 additions & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ const sidebars = {
collapsed: true,
items: [
'developer-guides/cosmwasm/walkthrough',
'developer-guides/cosmwasm/new-project',
]
},
'developer-guides/oracle-set-up-guide',
Expand Down

0 comments on commit d2c1ade

Please sign in to comment.