Skip to content

Commit

Permalink
feat(cli/docs): introduce devnet quickstart guide (#1080)
Browse files Browse the repository at this point in the history
Introduces scaffolding `hello-world-template` to CLI as default (and
using `--template` flag) and the quickstart page to the docs

task: https://app.asana.com/0/1206208509925075/1207372351528365/f
  • Loading branch information
idea404 authored May 22, 2024
1 parent 1d535e1 commit fdc49c4
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 8 deletions.
21 changes: 15 additions & 6 deletions cli/cmd/develop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bytes"
"context"
"os"
"os/exec"

Expand All @@ -25,22 +26,29 @@ func newDeveloperCmds() *cobra.Command {
}

func newForgeProjectCmd() *cobra.Command {
var cfg developerForgeProjectConfig

cmd := &cobra.Command{
Use: "new",
Short: "Scaffold a Forge project",
Long: `Scaffold a new Forge project with a XGreeter contract
accompanied by simple mocked testing and a multi-chain deployment script.`,
Args: cobra.NoArgs,
Long: `Scaffold a new Forge project accompanied by simple mocked testing and a multi-chain deployment script.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return newForgeProjectTemplate()
return newForgeProjectTemplate(cmd.Context(), cfg)
},
}

bindDeveloperForgeProjectConfig(cmd, &cfg)

return cmd
}

type developerForgeProjectConfig struct {
templateName string
}

// newForgeProjectTemplate creates a new project using the forge template.
func newForgeProjectTemplate() error {
func newForgeProjectTemplate(_ context.Context, cfg developerForgeProjectConfig) error {
// Check if forge is installed
if !checkForgeInstalled() {
// Forge is not installed, return an error with a suggestion.
Expand All @@ -51,7 +59,8 @@ func newForgeProjectTemplate() error {
}

// Execute the `forge init` command.
cmd := exec.Command("forge", "init", "--template", "https://github.com/omni-network/omni-forge-template.git")
// #nosec G204
cmd := exec.Command("forge", "init", "--template", "https://github.com/omni-network/"+cfg.templateName+".git")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cli/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func bindAVSAddress(cmd *cobra.Command, addr *string) {
cmd.Flags().StringVar(addr, "avs-address", *addr, "Optional address of the Omni AVS contract")
}

func bindDeveloperForgeProjectConfig(cmd *cobra.Command, cfg *developerForgeProjectConfig) {
cmd.Flags().StringVar(&cfg.templateName, "template", "hello-world-template", "Name of the forge template repo to use found in the omni-network github organization")
}

func bindDevnetAVSAllowConfig(cmd *cobra.Command, cfg *devnetAllowConfig) {
bindRPCURL(cmd, &cfg.RPCURL)
bindAVSAddress(cmd, &cfg.AVSAddr)
Expand Down
119 changes: 119 additions & 0 deletions docs/site/docs/develop/quickstart/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
sidebar_position: 1
---

# 3-Minute Cross-Chain dApp

This QuickStart guide will run through how to start an Omni cross chain dApp in less than three minutes.

In this guide you will:

- Install the Omni CLI, scaffold a new project and run a local devnet
- Deploy contracts using foundry to the local devnet and test their functionality

## Steps

### Step 1: Install the Omni CLI

First, install the Omni CLI by running the following command:

```bash
curl -sSfL https://raw.githubusercontent.com/omni-network/omni/main/scripts/install_omni_cli.sh | sh -s
```

You may otherwise install from source by following the steps shown in the [Omni CLI Tools section](../../tools/cli/cli.md).

### Step 2: Scaffold a new project

Next, create a new directory for your project and scaffold a new project using the Omni CLI:

```bash
mkdir my-omni-dapp
cd my-omni-dapp
omni developer new
```

Note: this requires [foundry](https://github.com/foundry-rs/foundry) to be installed on your machine.

<details>
<summary>Test the Contracts with Forge</summary>

You can test the contracts with Forge by running the following command:

```bash
forge test
```

</details>

### Step 3: Run a local devnet

Start a local devnet by running the following command:

```bash
omni devnet start
```

Note: this requires [Docker](https://docs.docker.com/get-docker/) to be installed on your machine.

### Step 4: Deploy contracts

Deploy the contracts to the local devnet using foundry:

<details>
<summary>Obtaining Parameter Values</summary>

You can obtain RPC URL values and portal addresses for the running devnet chains by running the following command:

```bash
omni devnet info
```

And you the private key value is the first anvil private key, found by running:

```bash
anvil
```

These values are kept in `./script/bash/.env.example` and are used to deploy the contracts. You can rename the file to `.env` and fill in the values for other networks.

</details>

```bash
bash script/bash/deploy.sh
```

### Step 5: Perform a Cross-Chain Greet

You can now perform a cross-rollup greet by running the following command:

<details>
<summary>Obtaining Deployment Addresses</summary>

You can obtain the XGreeter deployment addresses from the output of the previous forge script deployment.

Because the devnet has just been started, the addresses will be the same as the ones shown below:

```bash
omni_evm: 0x8464135c8F25Da09e49BC8782676a84730C318bC
mock_op: 0x8464135c8F25Da09e49BC8782676a84730C318bC
mock_arb: 0x8464135c8F25Da09e49BC8782676a84730C318bC
```

</details>

```bash
cast send 0x8464135c8F25Da09e49BC8782676a84730C318bC 'greet(string)' 'Yay in 3 minutes!' --private-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d --rpc-url http://localhost:8001 --value 1ether
```

### Step 6: Check the Greet

You can check the greet has been saved on the Omni EVM global state by running the following command:

```bash
cast call 0x8464135c8F25Da09e49BC8782676a84730C318bC "lastGreet():(uint64,uint256,uint256,address,address,string)" --rpc-url http://localhost:8000
```

### 🎉 Done 🎉

You have successfully deployed and interacted with an Omni cross-chain dApp in less than three minutes!
20 changes: 18 additions & 2 deletions docs/site/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ const sidebars: SidebarsConfig = {
},
{
type: "category",
label: "Testnet",
label: "Quickstart",
className: "sidebar-title",
collapsible: false,
items: [
{
type: "autogenerated",
dirName: "develop/testnet",
dirName: "develop/quickstart",
}
]
},
Expand All @@ -232,6 +232,22 @@ const sidebars: SidebarsConfig = {
type: "html",
value: "<div class='sidebar-separator'></div>",
},
{
type: "category",
label: "Testnet",
className: "sidebar-title",
collapsible: false,
items: [
{
type: "autogenerated",
dirName: "develop/testnet",
}
]
},
{
type: "html",
value: "<div class='sidebar-separator'></div>",
},
"develop/contracts",
],
operateSidebar: [
Expand Down

0 comments on commit fdc49c4

Please sign in to comment.