-
Notifications
You must be signed in to change notification settings - Fork 58
Add smart contract interaction tutorial under EVM section #424
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d714a6c
Add smart contract interaction tutorial under EVM section
yarikbratashchuk 2981872
Fix missing bracket
yarikbratashchuk 73463c7
Minor adjustments
yarikbratashchuk 96c4c27
Update tutorials/beaconkit.md
yarikbratashchuk 4ade58f
Update tutorials/beaconkit.md
yarikbratashchuk e66d23f
Update tutorials/beaconkit.md
yarikbratashchuk 80f9c56
Add blank line
yarikbratashchuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Smart Contract Interaction on EVM Rollup | ||
|
||
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. | ||
|
||
## Install Foundry | ||
|
||
To install Foundry, run the following commands: | ||
|
||
```bash | ||
curl -L https://foundry.paradigm.xyz | bash | ||
foundryup | ||
``` | ||
|
||
## Funds | ||
|
||
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): | ||
|
||
```bash | ||
PrivateKey: 0xfffdbb37105441e14b0ee6330d855d8504ff39e705c3afa8f859ac9865f99306 | ||
Address: 0x20f33CE90A13a4b5E7697E3544c3083B8F8A51D4 | ||
``` | ||
Manav-Aggarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Frontend | ||
|
||
Now we will make a frontend with a smart contract on our EVM rollup. First, clone the GM Portal repository: | ||
|
||
```bash | ||
cd $HOME | ||
git clone https://github.com/rollkit/gm-portal.git | ||
cd gm-portal | ||
``` | ||
|
||
### Deploy the ooga booga portal contract | ||
|
||
Next, you will deploy the smart contract. | ||
Export the funded private key and RPC URL: | ||
|
||
```bash | ||
export PRIVATE_KEY=0xfffdbb37105441e14b0ee6330d855d8504ff39e705c3afa8f859ac9865f99306 | ||
export RPC_URL=<rpc url> | ||
``` | ||
yarikbratashchuk marked this conversation as resolved.
Show resolved
Hide resolved
Manav-Aggarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Use Foundry to deploy the contract to your EVM: | ||
|
||
```bash | ||
cd contracts | ||
forge script script/GmPortal.s.sol:GmPortalScript --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast | ||
``` | ||
|
||
A successful deployment's output will look similar to: | ||
|
||
```bash | ||
forge script script/GmPortal.s.sol:GmPortalScript --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast | ||
[⠒] Compiling... | ||
[⠑] Compiling 18 files with 0.8.20 | ||
[⠘] Solc 0.8.20 finished in 1.52s | ||
Compiler run successful! | ||
Script ran successfully. | ||
|
||
== Logs == | ||
i am a smart contract on EVM x Rollkit. gm! | ||
|
||
[...] | ||
|
||
## | ||
Waiting for receipts. | ||
⠉ [00:00:00] [######################] 1/1 receipts (0.0s) | ||
##### 2061 | ||
✅ [Success]Hash: 0xa174e9389633972458e6dce431d84736e0709e9406c1c3b14b5fa9ae0cdd6860 | ||
Contract Address: 0x18Df82C7E422A42D47345Ed86B0E935E9718eBda // [!code focus] | ||
Block: 682 | ||
Paid: 0.001528707003566983 ETH (509569 gas * 3.000000007 gwei) | ||
|
||
[...] | ||
``` | ||
|
||
From the contract deployment output, export your contract address: | ||
|
||
```bash | ||
export CONTRACT_ADDRESS=0x18Df82C7E422A42D47345Ed86B0E935E9718eBda | ||
``` | ||
|
||
### Interact with the contract | ||
|
||
Send an "ooga booga" to the contract: | ||
|
||
```bash | ||
cast send $CONTRACT_ADDRESS \ | ||
"gm(string)" "ooga booga" \ | ||
--private-key $PRIVATE_KEY \ | ||
--rpc-url $RPC_URL | ||
``` | ||
|
||
Get total (hex-encoded) GMs (ooga boogas): | ||
|
||
```bash | ||
cast call $CONTRACT_ADDRESS "getTotalGms()" --rpc-url $RPC_URL | ||
``` | ||
|
||
### Start and update the frontend | ||
|
||
Now, change into the frontend directory: | ||
|
||
```bash | ||
cd $HOME/gm-portal/frontend | ||
yarn && yarn dev | ||
``` | ||
|
||
Now, your frontend is running! We'll display and interact with our smart contract | ||
on our frontend. | ||
|
||
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: | ||
|
||
::: tip | ||
**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: | ||
|
||
```bash | ||
cd $HOME | ||
cp gm-portal/contracts/out/GmPortal.sol/GmPortal.json gm-portal/frontend | ||
``` | ||
::: | ||
|
||
### Interact with the frontend | ||
|
||
In order to interact with the contract on the frontend, you'll need to fund an account that you have in your Ethereum wallet | ||
or add the private key from above into your wallet. | ||
|
||
To transfer to an external account, use this command: | ||
|
||
```bash | ||
export RECEIVER=<receiver ETH address> | ||
cast send --private-key $PRIVATE_KEY $RECEIVER --value 1ether --rpc-url $RPC_URL | ||
``` | ||
|
||
_If you are in a different terminal than the one you set the private key in originally, | ||
you may need to set it again._ | ||
Manav-Aggarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Now, login with your wallet that you funded, and post a ooga booga on your ooga booga portal! | ||
|
||
 | ||
yarikbratashchuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Conclusion | ||
|
||
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.