Skip to content

Commit bc4e70e

Browse files
Add smart contract interaction tutorial under EVM section (#424)
* Add smart contract interaction tutorial under EVM section * Fix missing bracket * Minor adjustments * Update tutorials/beaconkit.md Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com> * Update tutorials/beaconkit.md Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com> * Update tutorials/beaconkit.md Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com> * Add blank line --------- Co-authored-by: Josh Stein <46639943+jcstein@users.noreply.github.com>
1 parent b8d1b7d commit bc4e70e

File tree

5 files changed

+194
-10
lines changed

5 files changed

+194
-10
lines changed

.vitepress/config.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,16 @@ function sidebarHome() {
248248
collapsed: true,
249249
items: [
250250
{ text: "CosmWasm rollup", link: "/tutorials/cosmwasm" },
251-
{ text: "Omni Octane EVM rollup", link: "/tutorials/octane-evm" },
252-
{ text: "Polaris EVM rollup", link: "/tutorials/polaris-evm" },
253-
{ text: "BeaconKit EVM", link: "/tutorials/beaconkit" },
254-
],
251+
{
252+
text: "EVM",
253+
collapsed: true,
254+
items: [
255+
{ text: "Omni Octane EVM", link: "/tutorials/octane-evm" },
256+
{ text: "BeaconKit EVM", link: "/tutorials/beaconkit" },
257+
{ text: "Contract interaction", link: "/tutorials/evm-contract-interaction" },
258+
]
259+
},
260+
],
255261
},
256262
],
257263
},

public/frontend-evm.png

579 KB
Loading

tutorials/beaconkit.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ You should now see output indicating that your Rollkit node is running, with log
7171
11:45AM INF beacon block successfully built 🛠️ duration=46.93036ms module=server service=validator slot=40 state_root=0x5f75afde5c6a596fa11c17e8c60ca291ffb31ae5c9a40392e0ceb4d45ab42037
7272
11:45AM INF received proposal with beacon_block=true blob_sidecars=true module=baseapp service=prepare-proposal
7373
11:45AM INF no blob sidecars to verify, skipping verifier 🧢 module=server service=blockchain slot=0x28
74+
11:45AM INF received proposal with beacon_block=true blob_sidecars=true module=baseapp service=prepare-proposal
75+
11:45AM INF no blob sidecars to verify, skipping verifier 🧢 module=server service=blockchain slot=0x28
7476
11:45AM INF received incoming beacon block 📫 module=server service=blockchain state_root=0x5f75afde5c6a596fa11c17e8c60ca291ffb31ae5c9a40392e0ceb4d45ab42037
7577
11:45AM INF calling new payload is_optimistic=false module=server payload_block_hash=0x2ff9329ffecc7f395cb72acb9fd81a6085e5d75101ab14b508f6418fbcd7d0b4 payload_parent_block_hash=0x88081d5e4c48de2f82464f2c8b4b46df8892fe921e5e9b13113ed2a62081d843 service=execution-engine
7678
11:45AM INF state root verification succeeded - accepting incoming beacon block 🏎️ module=server service=blockchain state_root=0x5f75afde5c6a596fa11c17e8c60ca291ffb31ae5c9a40392e0ceb4d45ab42037
@@ -88,18 +90,35 @@ You should now see output indicating that your Rollkit node is running, with log
8890
...
8991
```
9092

93+
## Smart Contract Deployment and Interaction
94+
95+
To deploy and interact with smart contracts on the BeaconKit EVM, you can use the tools you are already familiar with, follow our [Contract interaction tutorial](/tutorials/evm-contract-interaction) to get a hands on experience.
96+
97+
To fund your account with some tokens, modify a Geth genesis file and restart the Geth client:
98+
Open `$HOME/beacon-kit/testing/files/eth-genesis.json`, and add your account address and balance:
99+
100+
```bash
101+
"nonce": "0x0000000000000000",
102+
"timestamp": "0x0",
103+
"alloc": {
104+
"<your address>": { // [!code focus]
105+
"balance": "0x12345000000000000000000" // [!code focus]
106+
}, // [!code focus]
107+
"0x20f33ce90a13a4b5e7697e3544c3083b8f8a51d4": {
108+
"balance": "0x123450000000000000000"
109+
},
110+
```
111+
91112
## Conclusion
92113
93114
Congratulations! You've successfully set up a BeaconKit node using Rollkit, creating your own sovereign rollup. This setup demonstrates the basic functionality of combining BeaconKit with Rollkit.
94115
95116
## Next Steps
96117
97118
To further customize your rollup chain:
98-
99-
1. Explore the BeaconKit configuration files to adjust parameters.
100-
2. Experiment with different Rollkit settings to optimize performance.
101-
3. Consider implementing custom smart contracts on your rollup.
102-
4. Test the scalability and performance of your rollup under various conditions.
119+
1. Experiment with different Rollkit settings to optimize performance.
120+
2. Consider implementing custom smart contracts on your rollup.
121+
3. Test the scalability and performance of your rollup under various conditions.
103122
104123
## Troubleshooting
105124

tutorials/evm-contract-interaction.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Smart Contract Interaction on EVM Rollup
2+
3+
In this tutorial, you will deploy a smart contract to your EVM rollup and interact with it on a frontend. This tutorial assumes that you spinned up an EVM rollup, know it's RPC URL, and have funded an account on it.
4+
5+
## Install Foundry
6+
7+
To install Foundry, run the following commands:
8+
9+
```bash
10+
curl -L https://foundry.paradigm.xyz | bash
11+
foundryup
12+
```
13+
14+
## Funds
15+
16+
Here is the private key and derived address of the account for you to be used in this tutorial (make sure to fund it with some ETH):
17+
18+
```bash
19+
PrivateKey: 0xfffdbb37105441e14b0ee6330d855d8504ff39e705c3afa8f859ac9865f99306
20+
Address: 0x20f33CE90A13a4b5E7697E3544c3083B8F8A51D4
21+
```
22+
23+
## Frontend
24+
25+
Now we will make a frontend with a smart contract on our EVM rollup. First, clone the GM Portal repository:
26+
27+
```bash
28+
cd $HOME
29+
git clone https://github.com/rollkit/gm-portal.git
30+
cd gm-portal
31+
```
32+
33+
### Deploy the ooga booga portal contract
34+
35+
Next, you will deploy the smart contract.
36+
Export the funded private key and RPC URL:
37+
38+
```bash
39+
export PRIVATE_KEY=0xfffdbb37105441e14b0ee6330d855d8504ff39e705c3afa8f859ac9865f99306
40+
export RPC_URL=<rpc url>
41+
```
42+
43+
Use Foundry to deploy the contract to your EVM:
44+
45+
```bash
46+
cd contracts
47+
forge script script/GmPortal.s.sol:GmPortalScript --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
48+
```
49+
50+
A successful deployment's output will look similar to:
51+
52+
```bash
53+
forge script script/GmPortal.s.sol:GmPortalScript --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
54+
[⠒] Compiling...
55+
[⠑] Compiling 18 files with 0.8.20
56+
[⠘] Solc 0.8.20 finished in 1.52s
57+
Compiler run successful!
58+
Script ran successfully.
59+
60+
== Logs ==
61+
i am a smart contract on EVM x Rollkit. gm!
62+
63+
[...]
64+
65+
##
66+
Waiting for receipts.
67+
⠉ [00:00:00] [######################] 1/1 receipts (0.0s)
68+
##### 2061
69+
✅ [Success]Hash: 0xa174e9389633972458e6dce431d84736e0709e9406c1c3b14b5fa9ae0cdd6860
70+
Contract Address: 0x18Df82C7E422A42D47345Ed86B0E935E9718eBda // [!code focus]
71+
Block: 682
72+
Paid: 0.001528707003566983 ETH (509569 gas * 3.000000007 gwei)
73+
74+
[...]
75+
```
76+
77+
From the contract deployment output, export your contract address:
78+
79+
```bash
80+
export CONTRACT_ADDRESS=0x18Df82C7E422A42D47345Ed86B0E935E9718eBda
81+
```
82+
83+
### Interact with the contract
84+
85+
Send an "ooga booga" to the contract:
86+
87+
```bash
88+
cast send $CONTRACT_ADDRESS \
89+
"gm(string)" "ooga booga" \
90+
--private-key $PRIVATE_KEY \
91+
--rpc-url $RPC_URL
92+
```
93+
94+
Get total (hex-encoded) GMs (ooga boogas):
95+
96+
```bash
97+
cast call $CONTRACT_ADDRESS "getTotalGms()" --rpc-url $RPC_URL
98+
```
99+
100+
### Start and update the frontend
101+
102+
Now, change into the frontend directory:
103+
104+
```bash
105+
cd $HOME/gm-portal/frontend
106+
yarn && yarn dev
107+
```
108+
109+
Now, your frontend is running! We'll display and interact with our smart contract
110+
on our frontend.
111+
112+
First, you will need to change the contract address on `gm-portal/frontend/src/App.tsx` to your contract address from above before you can interact with the contract on the frontend:
113+
114+
::: tip
115+
**Only if you changed the contract**, you will need to update the ABI in `gm-portal/frontend/GmPortal.json` from `gm-portal/contracts/out/GmPortal.sol/GmPortal.json`. This can be done with:
116+
117+
```bash
118+
cd $HOME
119+
cp gm-portal/contracts/out/GmPortal.sol/GmPortal.json gm-portal/frontend
120+
```
121+
:::
122+
123+
### Interact with the frontend
124+
125+
In order to interact with the contract on the frontend, you'll need to fund an account that you have in your Ethereum wallet
126+
or add the private key from above into your wallet.
127+
128+
To transfer to an external account, use this command:
129+
130+
```bash
131+
export RECEIVER=<receiver ETH address>
132+
cast send --private-key $PRIVATE_KEY $RECEIVER --value 1ether --rpc-url $RPC_URL
133+
```
134+
135+
_If you are in a different terminal than the one you set the private key in originally,
136+
you may need to set it again._
137+
138+
Now, login with your wallet that you funded, and post a ooga booga on your ooga booga portal!
139+
140+
![frontend-evm](/frontend-evm.png)
141+
142+
### Conclusion
143+
144+
You have successfully deployed a smart contract to your EVM rollup and interacted with it on a frontend. You can now build more complex applications on your EVM rollup!

tutorials/octane-evm.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,22 @@ To start your Omni node with Rollkit and local-DA, execute:
4848
make devnet-zero-deploy
4949
```
5050

51-
Upon execution, the command will set up and start your Omni node. You should see output indicating the progress and status of your node.
51+
Upon execution, the command will set up and start your Omni node. You should see output indicating the progress and status of your node. Notice the `EVM Chain RPC available` message, which indicates that the Omni node is ready to accept EVM transactions:
52+
53+
```bash
54+
24-07-22 20:29:03.655 INFO EVM Chain RPC available chain_id=1651 chain_name=omni_evm url=http://127.0.0.1:8000
55+
```
56+
57+
## 🧪 Smart Contract Deployment and Interaction
58+
59+
To deploy and interact with smart contracts on the Omni EVM, you can use the tools you are already familiar with, follow our [Contract interaction tutorial](/tutorials/evm-contract-interaction) to get a hands on experience.
60+
61+
To fund your account with some tokens, you can use the omni-cli, which needs to be installed first:
62+
63+
```bash
64+
make install-cli # install omni cli
65+
omni devnet fund --rpc-url http://127.0.0.1:8000 --address=<your address>
66+
```
5267

5368
## 🛑 Stopping the node
5469

0 commit comments

Comments
 (0)