Skip to content

Commit a047e11

Browse files
Cosmwasm tutorial adapted for local da (#389)
* Cosmwasm tutorial adapted for local da * Minor updates after review * Update
1 parent 4f667eb commit a047e11

File tree

2 files changed

+26
-76
lines changed

2 files changed

+26
-76
lines changed

public/cosmwasm/init.sh

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,13 @@
22

33
# set variables for the chain
44
VALIDATOR_NAME=validator1
5-
CHAIN_ID=celeswasm
6-
KEY_NAME=celeswasm-key
5+
CHAIN_ID=localwasm
6+
KEY_NAME=localwasm-key
77
TOKEN_AMOUNT="10000000000000000000000000uwasm"
88
STAKING_AMOUNT=1000000000uwasm
99
CHAINFLAG="--chain-id ${CHAIN_ID}"
1010
TXFLAG="--chain-id ${CHAIN_ID} --gas-prices 0uwasm --gas auto --gas-adjustment 1.3"
1111

12-
# query the DA Layer start height, in this case we are querying
13-
# an RPC endpoint provided by Celestia Labs. The RPC endpoint is
14-
# to allow users to interact with Celestia's core network by querying
15-
# the node's state and broadcasting transactions on the Celestia
16-
# network. This is for Arabica, if using another network, change the RPC.
17-
DA_BLOCK_HEIGHT=$(curl https://rpc-mocha.pops.one/block |jq -r '.result.block.header.height')
18-
echo -e "\n Your DA_BLOCK_HEIGHT is $DA_BLOCK_HEIGHT \n"
19-
20-
AUTH_TOKEN=$(celestia light auth write --p2p.network mocha)
21-
echo -e "\n Your DA AUTH_TOKEN is $AUTH_TOKEN \n"
22-
2312
# reset any existing genesis/chain data
2413
wasmd tendermint unsafe-reset-all
2514
wasmd init $VALIDATOR_NAME --chain-id $CHAIN_ID
@@ -54,12 +43,7 @@ ADDRESS=$(jq -r '.address' ~/.wasmd/config/priv_validator_key.json)
5443
PUB_KEY=$(jq -r '.pub_key' ~/.wasmd/config/priv_validator_key.json)
5544
jq --argjson pubKey "$PUB_KEY" '.consensus["validators"]=[{"address": "'$ADDRESS'", "pub_key": $pubKey, "power": "1000", "name": "Rollkit Sequencer"}]' ~/.wasmd/config/genesis.json > temp.json && mv temp.json ~/.wasmd/config/genesis.json
5645

57-
# create a restart-testnet.sh file to restart the chain later
58-
[ -f restart-wasmd.sh ] && rm restart-wasmd.sh
59-
echo "DA_BLOCK_HEIGHT=$DA_BLOCK_HEIGHT" >> restart-wasmd.sh
60-
echo "AUTH_TOKEN=$AUTH_TOKEN" >> restart-wasmd.sh
61-
62-
echo "wasmd start --rollkit.aggregator --rollkit.da_auth_token=\$AUTH_TOKEN --rollkit.da_namespace 00000000000000000000000000000000000000000008e5f679bf7116cb --rollkit.da_start_height \$DA_BLOCK_HEIGHT --rpc.laddr tcp://127.0.0.1:36657 --grpc.address 127.0.0.1:9290 --p2p.laddr \"0.0.0.0:36656\" --minimum-gas-prices="0.025uwasm"" >> restart-wasmd.sh
46+
echo "wasmd start --rollkit.aggregator --rollkit.da_address http://localhost:7980 --rpc.laddr tcp://127.0.0.1:36657 --grpc.address 127.0.0.1:9290 --p2p.laddr \"0.0.0.0:36656\" --minimum-gas-prices="0.025uwasm"" >> restart-wasmd.sh
6347

6448
# start the chain
65-
wasmd start --rollkit.aggregator --rollkit.da_auth_token=$AUTH_TOKEN --rollkit.da_namespace 00000000000000000000000000000000000000000008e5f679bf7116cb --rollkit.da_start_height $DA_BLOCK_HEIGHT --rpc.laddr tcp://127.0.0.1:36657 --grpc.address 127.0.0.1:9290 --p2p.laddr "0.0.0.0:36656" --minimum-gas-prices="0.025uwasm"
49+
wasmd start --rollkit.aggregator --rollkit.da_address http://localhost:7980 --rpc.laddr tcp://127.0.0.1:36657 --grpc.address 127.0.0.1:9290 --p2p.laddr "0.0.0.0:36656" --minimum-gas-prices="0.025uwasm"

tutorials/cosmwasm.md

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
CosmWasm is a smart contracting platform built for the Cosmos
44
ecosystem by making use of [WebAssembly](https://webassembly.org) (Wasm)
55
to build smart contracts for Cosmos-SDK. In this tutorial, we will be
6-
exploring how to integrate CosmWasm with Celestia's
7-
[data availability layer](https://docs.celestia.org/concepts/how-celestia-works/data-availability-layer)
8-
using Rollkit.
6+
exploring how to integrate CosmWasm with local DA layer using Rollkit.
97

108
<!-- markdownlint-disable MD033 -->
119
<script setup>
@@ -17,40 +15,25 @@ import Callout from '../.vitepress/components/callout.vue'
1715
:::
1816
<!-- markdownlint-enable MD033 -->
1917

20-
::: warning
21-
The script for this tutorial is built for Celestia's
22-
[Mocha testnet](https://docs.celestia.org/nodes/mocha-testnet).
23-
:::
24-
25-
You can learn more about CosmWasm [here](https://docs.cosmwasm.com/docs/).
26-
2718
The smart contract we will use for this tutorial is one provided by
2819
the CosmWasm team for Nameservice purchasing.
2920

3021
You can check out the contract [here](https://github.com/InterWasm/cw-contracts/tree/main/contracts/nameservice).
3122

3223
How to write the Rust smart contract for Nameservice is outside the scope of
33-
this tutorial. In the future we will add more tutorials for writing CosmWasm
34-
smart contracts for Celestia.
24+
this tutorial.
3525

3626
## 💻 CosmWasm dependency installations {#dependencies}
3727

38-
### 🛠️ Environment setup {#environment}
39-
40-
For this tutorial, we will be using `curl` and `jq` as helpful
41-
tools. You can follow the guide on installing them
42-
[here](https://docs.celestia.org/nodes/environment/#-install-wget-and-jq).
28+
### 🏃 Golang {#install-go}
4329

44-
### 🏃 Golang dependency {#install-golang}
30+
For this tutorial, we will need `go` and `jq` installed on your machine. You can install them by running our script:
4531

46-
The Golang version used for this tutorial is v1.19+
47-
48-
You can install Golang
49-
by following our tutorial [here](https://docs.celestia.org/nodes/environment#install-golang).
50-
51-
### 🦀 Rust installation {#install-rust}
32+
```bash
33+
curl -sSL https://rollkit.dev/install-go.sh | bash -s go1.22.3
34+
```
5235

53-
#### 🔨 Rustup {#rustup}
36+
### 🦀 Rust {#install-rust}
5437

5538
First, before installing Rust, you would need to install `rustup`.
5639

@@ -118,7 +101,7 @@ Find the right instructions specific for
118101
119102
Here, we are going to pull down the `wasmd` repository and replace CometBFT
120103
with Rollkit. Rollkit is a drop-in replacement for CometBFT that allows
121-
Cosmos-SDK applications to connect to Celestia's data availability network.
104+
Cosmos-SDK applications to connect to data availability (DA) network.
122105
123106
```bash
124107
git clone https://github.com/CosmWasm/wasmd.git
@@ -150,22 +133,16 @@ make install
150133
You will have to install `gcc` if you are trying it on a clean linux vm.
151134
:::
152135
153-
### ✨ Celestia node {#celestia-node}
154-
155-
You will need a light node running with test tokens on
156-
[Mocha testnet](https://docs.celestia.org/nodes/mocha-testnet) in order
157-
to complete this tutorial. Complete [the tutorial](https://docs.celestia.org/developers/node-tutorial)
158-
and start up your node.
136+
### ✨ Local DA node {#local-da-node}
159137
160-
Be sure you have initialized your node before trying to start it.
161-
Your start command should look similar to:
138+
You will need a local-da node running in order to complete this tutorial. To start it, run:
162139
163-
<!-- markdownlint-disable MD013 -->
164140
```bash
165-
celestia light start --core.ip rpc-mocha.pops.one --p2p.network mocha
141+
curl -sSL https://rollkit.dev/install-local-da.sh | bash -s v0.2.0
166142
```
167143
168-
## 🌌 Setting up your environment for CosmWasm on Celestia {#setting-up-environment-on-celestia}
144+
145+
## 🌌 Setting up your environment for CosmWasm on local-da {#setting-up-environment-on-local-da}
169146
170147
Now the `wasmd` binary is built, we need to setup a local network
171148
that communicates between `wasmd` and Rollkit.
@@ -197,10 +174,6 @@ bash init.sh
197174
198175
With that, we have kickstarted our `wasmd` network!
199176
200-
View your rollup by
201-
[finding your namespace or account Celenium](https://celenium.io).
202-
203-
[View the example rollup's namespace on Celenium](https://celenium.io/namespace/000000000000000000000000000000000000000008e5f679bf7116cb).
204177
205178
### 💠 Optional: see what's inside the script {#view-script}
206179

@@ -282,28 +255,25 @@ Run the following in the `~/cw-contracts/contracts/nameservice` directory:
282255
283256
<!-- markdownlint-disable MD013 -->
284257
```bash [AMD Machines]
285-
TX_HASH=$(wasmd tx wasm store artifacts/cw_nameservice.wasm --from celeswasm-key --keyring-backend test --chain-id celeswasm --gas-prices 0.025uwasm --gas auto --gas-adjustment 1.3 --node http://127.0.0.1:36657 --output json -y | jq -r '.txhash') && echo $TX_HASH
258+
TX_HASH=$(wasmd tx wasm store artifacts/cw_nameservice.wasm --from localwasm-key --keyring-backend test --chain-id localwasm --gas-prices 0.025uwasm --gas auto --gas-adjustment 1.3 --node http://127.0.0.1:36657 --output json -y | jq -r '.txhash') && echo $TX_HASH
286259
```
287260
<!-- markdownlint-enable MD013 -->
288261
289262
<!-- markdownlint-disable MD013 -->
290263
```bash [ARM Machines]
291-
TX_HASH=$(wasmd tx wasm store artifacts/cw_nameservice-aarch64.wasm --from celeswasm-key --keyring-backend test --chain-id celeswasm --gas-prices 0.025uwasm --gas auto --gas-adjustment 1.3 --node http://127.0.0.1:36657 --output json -y | jq -r '.txhash') && echo $TX_HASH
264+
TX_HASH=$(wasmd tx wasm store artifacts/cw_nameservice-aarch64.wasm --from localwasm-key --keyring-backend test --chain-id localwasm --gas-prices 0.025uwasm --gas auto --gas-adjustment 1.3 --node http://127.0.0.1:36657 --output json -y | jq -r '.txhash') && echo $TX_HASH
292265
293266
:::
294267
295-
This will get you the transaction hash for the smart contract deployment. Given
296-
we are using Rollkit, there will be a delay on the transaction being included
297-
due to Rollkit waiting on Celestia's data availability layer to confirm the block
298-
has been included before submitting a new block.
268+
This will get you the transaction hash for the smart contract deployment.
299269
300270
::: danger
301271
If you run into errors with variables on the previous command,
302272
or commands in the remainder of the tutorial, cross-reference
303273
the variables in the command with the variables in the `init.sh` script.
304274
:::
305275
306-
## 🌟 Contract interaction on CosmWasm with Celestia {#contract-interaction-on-celestia}
276+
## 🌟 Contract interaction on CosmWasm {#contract-interaction-on-local-da}
307277
<!-- markdownlint-disable MD013 -->
308278
309279
In the previous steps, we have stored out contract's tx hash in an
@@ -312,13 +282,9 @@ environment variable for later use.
312282
The following guide will show you how to deploy and interact with a contract using CLI.
313283
For scripting using Rust, you can use [cw-orchestrator](/guides/cw-orch.md).
314284

315-
Because of the longer time periods of submitting transactions via Rollkit
316-
due to waiting on Celestia's data availability layer to confirm block inclusion,
317-
we will need to query our tx hash directly to get information about it.
318-
319285
### 🔎 Contract querying {#contract-querying}
320286

321-
Let's start by querying our transaction hash for its code ID:
287+
Now, let's query our transaction hash for its code ID:
322288
323289
```bash
324290
CODE_ID=$(wasmd query tx --type=hash $TX_HASH --node http://127.0.0.1:36657 --output json | jq -r '.events[-1].attributes[1].value')
@@ -350,7 +316,7 @@ is `100uwasm` and `transfer_price` is `999uwasm`.
350316

351317
```bash
352318
INIT='{"purchase_price":{"amount":"100","denom":"uwasm"},"transfer_price":{"amount":"999","denom":"uwasm"}}'
353-
wasmd tx wasm instantiate $CODE_ID "$INIT" --from celeswasm-key --keyring-backend test --label "name service" --chain-id celeswasm --gas-prices 0.025uwasm --gas auto --gas-adjustment 1.3 -y --no-admin --node http://127.0.0.1:36657
319+
wasmd tx wasm instantiate $CODE_ID "$INIT" --from localwasm-key --keyring-backend test --label "name service" --chain-id localwasm --gas-prices 0.025uwasm --gas auto --gas-adjustment 1.3 -y --no-admin --node http://127.0.0.1:36657
354320
```
355321

356322
### 📄 Contract interaction {#contract-interaction}
@@ -393,7 +359,7 @@ Now, let's register a name to the contract for our wallet address:
393359
394360
```bash
395361
REGISTER='{"register":{"name":"fred"}}'
396-
wasmd tx wasm execute $CONTRACT "$REGISTER" --amount 100uwasm --from celeswasm-key --chain-id celeswasm --gas-prices 0.025uwasm --gas auto --gas-adjustment 1.3 --node http://127.0.0.1:36657 --keyring-backend test -y
362+
wasmd tx wasm execute $CONTRACT "$REGISTER" --amount 100uwasm --from localwasm-key --chain-id localwasm --gas-prices 0.025uwasm --gas auto --gas-adjustment 1.3 --node http://127.0.0.1:36657 --keyring-backend test -y
397363
```
398364
399365
Your output will look similar to below:
@@ -436,4 +402,4 @@ You'll see the owner's address in a JSON response:
436402
```
437403

438404
With that, we have instantiated and interacted with the CosmWasm nameservice
439-
smart contract using Celestia!
405+
smart contract on our local DA network using Rollkit!

0 commit comments

Comments
 (0)