Skip to content

Commit e12cf3b

Browse files
Merge branch 'main' into yarik/cosmwasm-local-da
2 parents f94b4d0 + 4f667eb commit e12cf3b

File tree

3 files changed

+309
-0
lines changed

3 files changed

+309
-0
lines changed

.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ function sidebarHome() {
289289
text: "How to integrate Range with your rollup",
290290
link: "/guides/rollkit-monitoring",
291291
},
292+
{
293+
text: "How to use IBC token (TIA) as gas token in your rollup",
294+
link: "/guides/use-tia-for-gas",
295+
},
292296
],
293297
},
294298
],

guides/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ In this section, you'll find:
2323
* [How to use lazy sequencing (aggregation)](/guides/lazy-sequencing.md)
2424
* [Testing and deploying smart-contract with cw-orch](/guides/cw-orch.md)
2525
* [How to integrate Range with your rollup](/guides/rollkit-monitoring.md)
26+
* [How to use IBC token (TIA) as gas token in your rollup](/guides/use-tia-for-gas.md)
2627

2728
## 💻 Support {#support}
2829

guides/use-tia-for-gas.md

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
---
2+
description: Build a sovereign rollup using Rollkit CLI and a local DA network, with TIA as the gas token.
3+
---
4+
5+
# How to use IBC token (TIA) as gas token in your rollup
6+
7+
## 🌞 Introduction {#introduction}
8+
9+
This tutorial will guide you through building a sovereign `gm-world` rollup using Rollkit, with TIA as the gas token. Unlike the [quick start guide](https://rollkit.dev/tutorials/quick-start), which uses a native rollup token for gas, this tutorial demonstrates how to integrate an IBC-enabled token, TIA, as the gas token within the rollup, providing a deeper exploration of sovereign rollup development.
10+
11+
We will cover:
12+
13+
- Building and configuring a Cosmos-SDK application-specific rollup blockchain.
14+
- Posting rollup data to a Data Availability (DA) network.
15+
- Executing transactions using TIA as the gas token (the end goal).
16+
17+
No prior understanding of the build process is required, just that it utilizes the [Cosmos SDK](https://github.com/cosmos/cosmos-sdk) for blockchain applications.
18+
19+
<!-- markdownlint-disable MD033 -->
20+
<script setup>
21+
import Callout from '../.vitepress/components/callout.vue'
22+
import constants from '../.vitepress/constants/constants.js'
23+
</script>
24+
25+
:::tip
26+
<Callout />
27+
:::
28+
29+
<!-- markdownlint-enable MD033 -->
30+
31+
## 🛠️ Dependencies {#dependencies}
32+
33+
Rollkit uses the [Go programming language](https://go.dev/dl/). Here's how to install it:
34+
35+
- **Linux or macOS**: Run the provided script:
36+
37+
```bash-vue
38+
curl -sSL https://rollkit.dev/install-go.sh | bash -s {{constants.golangVersion}}
39+
```
40+
41+
<!-- markdownlint-disable MD033 -->
42+
43+
- **Windows**: Download and execute the <a :href="`https://go.dev/dl/go${constants.golangVersion}.windows-amd64.msi`">installer</a>.
44+
<!-- markdownlint-enable MD033 -->
45+
46+
## 🌐 Running a Local DA Network {#running-local-da}
47+
48+
Learn to run a local DA network, designed for educational purposes, on your machine.
49+
50+
To set up a local DA network node:
51+
52+
```bash-vue
53+
(cd /tmp && curl -sSL https://rollkit.dev/install-local-da.sh | bash -s {{constants.localDALatestTag}})
54+
```
55+
56+
This script builds and runs the node, now listening on port `7980`.
57+
58+
## 🏗️ Building Your Sovereign Rollup {#building-your-sovereign-rollup}
59+
60+
With the local DA network running, let’s prepare your rollup blockchain.
61+
62+
To make it simple, we will download a repository with a `gm-world` rollup that includes an `init.sh` script to handle all the setup for you.
63+
64+
Download and build a `gm-world` rollup with an interactive script in a new terminal:
65+
66+
::: warning
67+
Ensure the `jq` command line tool is installed before proceeding. Install it using `sudo apt-get install jq` on Ubuntu or `brew install jq` on macOS.
68+
:::
69+
::: tip
70+
If you get errors of `gmd` not found, you may need to add the `go/bin` directory to your PATH. You can do this by running `export PATH=$PATH:$HOME/go/bin` and then running the `init.sh` script manually again.
71+
:::
72+
73+
```bash
74+
(cd /tmp && bash -c "$(curl -sSL https://rollkit.dev/install-gm-rollup.sh)")
75+
```
76+
77+
## 🚀 Starting your rollup {#start-your-rollup}
78+
79+
Start the rollup, posting to the local DA network:
80+
81+
```bash
82+
gmd start --rollkit.aggregator --rollkit.da_address http://localhost:7980 --minimum-gas-prices="0.02ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA,0.025stake"
83+
```
84+
85+
Note that we specified the gas token to be IBC TIA. We still haven't made an IBC connection to Celestia's Mocha testnet, however, if we assume our first channel will be an ICS-20 transfer channel to Celestia, we can already calculate the token denom using this formula:
86+
87+
```js
88+
"ibc/" + toHex(sha256(toUtf8("transfer/channel-0/utia"))).toUpperCase();
89+
```
90+
91+
Now you should see the logs of the running node:
92+
93+
```bash
94+
12:21PM INF starting node with ABCI CometBFT in-process module=server
95+
12:21PM INF starting node with Rollkit in-process module=server
96+
12:21PM INF service start impl=multiAppConn module=proxy msg="Starting multiAppConn service"
97+
12:21PM INF service start connection=query impl=localClient module=abci-client msg="Starting localClient service"
98+
12:21PM INF service start connection=snapshot impl=localClient module=abci-client msg="Starting localClient service"
99+
12:21PM INF service start connection=mempool impl=localClient module=abci-client msg="Starting localClient service"
100+
12:21PM INF service start connection=consensus impl=localClient module=abci-client msg="Starting localClient service"
101+
12:21PM INF service start impl=EventBus module=events msg="Starting EventBus service"
102+
12:21PM INF service start impl=PubSub module=pubsub msg="Starting PubSub service"
103+
12:21PM INF Using default mempool ttl MempoolTTL=25 module=BlockManager
104+
12:21PM INF service start impl=IndexerService module=txindex msg="Starting IndexerService service"
105+
12:21PM INF service start impl=RPC module=server msg="Starting RPC service"
106+
12:21PM INF service start impl=Node module=server msg="Starting Node service"
107+
12:21PM INF starting P2P client module=server
108+
12:21PM INF serving HTTP listen address=127.0.0.1:26657 module=server
109+
12:21PM INF listening on address=/ip4/127.0.0.1/tcp/26656/p2p/12D3KooWSicdPmMTLf9fJbSSHZc9UVP1CbNqKPpbYVbgxHvbhAUY module=p2p
110+
12:21PM INF listening on address=/ip4/163.172.162.109/tcp/26656/p2p/12D3KooWSicdPmMTLf9fJbSSHZc9UVP1CbNqKPpbYVbgxHvbhAUY module=p2p
111+
12:21PM INF no seed nodes - only listening for connections module=p2p
112+
12:21PM INF working in aggregator mode block time=1000 module=server
113+
12:21PM INF Creating and publishing block height=22 module=BlockManager
114+
12:21PM INF starting gRPC server... address=127.0.0.1:9290 module=grpc-server
115+
12:21PM INF finalized block block_app_hash=235D3710D61F347DBBBDD6FD63AA7687842D1EF9CB475C712856D7DA32F82F09 height=22 module=BlockManager num_txs_res=0 num_val_updates=0
116+
12:21PM INF executed block app_hash=235D3710D61F347DBBBDD6FD63AA7687842D1EF9CB475C712856D7DA32F82F09 height=22 module=BlockManager
117+
12:21PM INF indexed block events height=22 module=txindex
118+
...
119+
```
120+
121+
## ✨ Connecting to Celestia Mocha testnet using IBC {#ibc-to-celestia}
122+
123+
Next, we will establish an IBC connection with the Celestia Mocha testnet to enable TIA transfers for gas usage on our rollup.
124+
125+
Install the IBC relayer:
126+
127+
```bash
128+
git clone --depth 1 --branch v2.5.2 https://github.com/cosmos/relayer.git /tmp/relayer
129+
cd /tmp/relayer
130+
make install
131+
```
132+
133+
Configure the relayer:
134+
135+
```bash
136+
rly config init
137+
138+
mkdir -p "$HOME/.relayer/keys/{gm,mocha-4}"
139+
140+
echo "global:
141+
api-listen-addr: :5183
142+
timeout: 10s
143+
memo: ''
144+
light-cache-size: 20
145+
log-level: info
146+
ics20-memo-limit: 0
147+
max-receiver-size: 150
148+
chains:
149+
gm_rollup:
150+
type: cosmos
151+
value:
152+
key-directory: '$HOME/.relayer/keys/gm'
153+
key: a
154+
chain-id: gm
155+
rpc-addr: http://localhost:26657
156+
account-prefix: gm
157+
keyring-backend: test
158+
gas-adjustment: 1.5
159+
gas-prices: 0.025stake
160+
min-gas-amount: 0
161+
max-gas-amount: 0
162+
debug: false
163+
timeout: 20s
164+
block-timeout: ''
165+
output-format: json
166+
sign-mode: direct
167+
extra-codecs: []
168+
coin-type: 118
169+
signing-algorithm: ''
170+
broadcast-mode: batch
171+
min-loop-duration: 0s
172+
extension-options: []
173+
feegrants: null
174+
mocha:
175+
type: cosmos
176+
value:
177+
key-directory: '$HOME/.relayer/keys/mocha-4'
178+
key: a
179+
chain-id: mocha-4
180+
rpc-addr: https://celestia-testnet-rpc.publicnode.com:443
181+
account-prefix: celestia
182+
keyring-backend: test
183+
gas-adjustment: 1.5
184+
gas-prices: 0.15utia
185+
min-gas-amount: 0
186+
max-gas-amount: 0
187+
debug: false
188+
timeout: 20s
189+
block-timeout: ''
190+
output-format: json
191+
sign-mode: direct
192+
extra-codecs: []
193+
coin-type: 118
194+
signing-algorithm: ''
195+
broadcast-mode: batch
196+
min-loop-duration: 0s
197+
extension-options: []
198+
feegrants: null
199+
paths:
200+
gm_mocha-4:
201+
src:
202+
chain-id: gm
203+
dst:
204+
chain-id: mocha-4
205+
src-channel-filter:
206+
rule: ''
207+
channel-list: []
208+
" > "$HOME/.relayer/config/config.yaml"
209+
210+
rly keys restore gm_rollup a "regret resist either bid upon yellow leaf early symbol win market vital"
211+
rly keys restore mocha a "regret resist either bid upon yellow leaf early symbol win market vital"
212+
```
213+
214+
Get the relayer accounts:
215+
216+
```bash
217+
rly address gm_rollup a # => gm1jqevcsld0dqpjp3csfg7alkv3lehvn8uswknrc
218+
rly address mocha a # => celestia1jqevcsld0dqpjp3csfg7alkv3lehvn8u04ymsu
219+
```
220+
221+
Note: These accounts should always be the same because of the hardcoded mnemonics that we've loaded in the `rly keys restore` step.
222+
223+
Fund the relayer on our rollup:
224+
225+
```bash
226+
gmd tx bank send gm-key-2 gm1jqevcsld0dqpjp3csfg7alkv3lehvn8uswknrc 10000000stake --keyring-backend test --chain-id gm --fees 5000stake -y
227+
```
228+
229+
Fund the relayer on the Celestia Mocha testnet:
230+
231+
[Mocha Testnet Faucet Instructions](https://docs.celestia.org/nodes/mocha-testnet#mocha-testnet-faucet).
232+
233+
Verify the relayer is funded:
234+
235+
```bash
236+
rly q balance mocha a # => address {celestia1jqevcsld0dqpjp3csfg7alkv3lehvn8u04ymsu} balance {10000000utia}
237+
rly q balance gm_rollup a # => address {gm1jqevcsld0dqpjp3csfg7alkv3lehvn8uswknrc} balance {10000000stake}
238+
```
239+
240+
Create IBC clients:
241+
242+
```bash
243+
rly tx client gm_rollup mocha gm_mocha-4 --override
244+
rly tx client mocha gm_rollup gm_mocha-4 --override
245+
```
246+
247+
Create IBC connection:
248+
249+
```bash
250+
rly tx connection gm_mocha-4
251+
```
252+
253+
Create IBC channel:
254+
255+
```bash
256+
rly tx channel gm_mocha-4 --src-port transfer --dst-port transfer --version ics20-1
257+
```
258+
259+
Start the relayer:
260+
261+
```bash
262+
rly start gm_mocha-4
263+
```
264+
265+
Transfer TIA from Mocha to our rollup:
266+
267+
```bash
268+
ACCOUNT_ON_ROLLUP="$(gmd keys show -a --keyring-backend test gm-key-2)"
269+
CHANNEL_ID_ON_MOCHA="$(rly q channels mocha gm_rollup | jq -r .channel_id | tail -1)"
270+
271+
rly tx transfer mocha gm_rollup 1000000utia "$ACCOUNT_ON_ROLLUP" "$CHANNEL_ID_ON_MOCHA" --path gm_mocha-4
272+
```
273+
274+
Verify the account on our rollup is funded with IBC TIA:
275+
276+
```bash
277+
gmd q bank balances "$(gmd keys show -a --keyring-backend test gm-key-2)"
278+
# =>
279+
# balances:
280+
# - amount: "1000000"
281+
# denom: ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA
282+
# - amount: "9999999999999999989995000"
283+
# denom: stake
284+
# pagination:
285+
# total: "2"
286+
```
287+
288+
## 💸 Transactions {#transactions}
289+
290+
Finally, send a transaction on our rollup using IBC TIA as the gas token:
291+
292+
```bash
293+
ACCOUNT_ON_ROLLUP="$(gmd keys show -a --keyring-backend test gm-key-2)"
294+
295+
# Send the transaction
296+
TX_HASH=$(gmd tx bank send "$ACCOUNT_ON_ROLLUP" "$ACCOUNT_ON_ROLLUP" 1stake --keyring-backend test --chain-id gm --gas-prices 0.02ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA -y --output json | jq -r .txhash)
297+
298+
# Verify success
299+
gmd q tx "$TX_HASH" --output json | jq .code # => 0
300+
```
301+
302+
## 🎉 Next steps
303+
304+
Congratulations! You've built a local rollup that posts to a local DA network and uses TIA as the gas token!

0 commit comments

Comments
 (0)