bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 38쪽 중 22쪽
s clears your existing local Initia, Minitia,
OPinit, and relayer setup:
```bash wrap theme={null}
rm -rf ~/.weave ~/.initia ~/.minitia ~/.opinit
docker rm -f weave-relayer || true
```
</Warning>
**Run the following command in your terminal:**
```bash wrap theme={null}
weave init
```
Here's a guide on how to navigate the interactive setup:
<Steps>
<Step title="Foundation & Funding">
### Generate Gas Station Account
The Gas Station is an account on the Initia L1 that will fund your rollup's infrastructure.
**Prompt:**
```terminal wrap theme={null}
How would you like to set up your Gas Station account?
```
**Action:**
Select `Generate new account (recommended)`.
**Result:**
You will see your new Gas Station Address. Copy this address.
### Fund Your Gas Station Account
**Action:**
Go to the [Initia Testnet Faucet](https://app.testnet.initia.xyz/faucet).
**Action:**
Paste your address and click **Submit** to receive testnet INIT tokens.
**Prompt:**
```terminal wrap theme={null}
Type `continue` to proceed.
```
**Action:**
Type `continue` and press Enter.
</Step>
<Step title="Rollup Identity">
### Select Your Action
**Prompt:**
```terminal wrap theme={null}
What do you want to do?
```
**Action:**
Select `Launch a new rollup`.
<Warning>
**Switching VMs?** Reinstall the correct `minitiad` binary first (Step 6). If you have existing rollup data, type `confirm` when prompted to clean it and proceed.
</Warning>
### Select L1 Network
**Prompt:**
```terminal wrap theme={null}
Select the Initia L1 network
```
**Action:**
Select `Testnet (initiation-2)`.
### Select Virtual Machine (VM)
**Prompt:**
```terminal wrap theme={null}
Select the Virtual Machine (VM)
```
**Action:**
Select your desired VM (e.g., `Move`).
### Specify Rollup Chain ID
**Prompt:**
```terminal wrap theme={null}
Specify rollup chain ID
```
**Action:**
Enter a unique ID (e.g., `mygame-1`).
<Tip>
**Save your Chain ID!** You'll need this unique identifier for your final submission.
</Tip>
### Specify Rollup Gas Denom
**Prompt:**
```terminal wrap theme={null}
Specify rollup gas denom
```
**Action:**
Press `Tab` for default (`umin`) or enter your own.
### Specify Rollup Node Moniker
**Prompt:**
```terminal wrap theme={null}
Specify rollup node moniker
```
**Action:**
Press `Tab` for default (`operator`).
</Step>
<Step title="Network & Infrastructure">
### Submission Interval
**Prompt:**
```terminal wrap theme={null}
Specify OP bridge config: Submission Interval
```
**Action:**
Press `Tab` for default (`1m`).
### Finalization Period
**Prompt:**
```terminal wrap theme={null}
Specify OP bridge config: Output Finalization Period
```
**Action:**
Press `Tab` for default (`168h`).
### Data Availability
**Prompt:**
```terminal wrap theme={null}
Where should the rollup blocks data be submitted?
```
**Action:**
Select `Initia L1`.
### Enable Oracle Price Feed
**Prompt:**
```terminal wrap theme={null}
Would you like to enable oracle price feed from L1?
```
**Action:**
Select `Enable`.
</Step>
<Step title="Security & Genesis">
### Setup Method for System Keys
**Prompt:**
```terminal wrap theme={null}
Select a setup method for the system keys
```
**Action:**
Select `Generate new system keys`.
### System Accounts Funding Option
**Prompt:**
```terminal wrap theme={null}
Select system accounts funding option
```
**Action:**
Select `Use the default preset`.
### Specify Fee Whitelist Addresses
**Prompt:**
```terminal wrap theme={null}
Specify fee whitelist addresses
```
**Action:**
Press `Enter` to leave empty.
### Add Gas Station Account to Genesis
**Prompt:**
```terminal wrap theme={null}
Would you like to add the Gas Station account to genesis accounts?
```
**Action:**
Select `Yes`.
### Specify Genesis Balance
**Prompt:**
```terminal wrap theme={null}
Specify the genesis balance for the Gas Station account
```
**Action:**
Enter `1000000000000000000000000` (10^24). This ensures you have plenty of tokens for testing, especially for EVM.
<Warning>
**Move Track Balance Limit:** Use `10000000000000000000` (10^19) to avoid `u64` overflows.
</Warning>
### Add Additional Genesis Accounts
**Prompt:**
```terminal wrap theme={null}
Would you like to add genesis accounts?
```
**Action:**
Select `No`.
</Step>
<Step title="Launch">
### Verify System Keys & Continue
**Prompt:**
```terminal wrap theme={null}
Type 'continue' to proceed.
```
**Action:**
Type `continue` and press Enter.
### Confirm Transactions
**Prompt:**
```terminal wrap theme={null}
Confirm to proceed with signing and broadcasting the following transactions? [y]:
```
**Action:**
Type `y` and press Enter.
Your appchain will now launch and start producing blocks!
</Step>
</Steps>
## Step 8: Setup Interwoven Bots
To enable the Optimistic bridge and cross-chain communication (IBC) between
Initia L1 and your appchain, you need to start the `OPinit Executor` and the
`IBC Relayer`. These bots manage the cross-chain connectivity of your chain.
<Note>
**Prerequisite:** Your appchain must be running before configuring these bots. Because `weave init` runs your chain in the background, you can continue using the same terminal window.
</Note>
### 8.1 Start the OPinit Executor
The executor handles the submission of rollup data and bridge operations.
**Run the following command:**
```bash wrap theme={null}
weave opinit init executor
```
Follow the interactive guide:
<Steps>
<Step title="Use Detected Keys">
**Prompt:**
```terminal wrap theme={null}
Existing keys in config.json detected. Would you like to add these to the keyring before proceeding?
```
**Action:**
Select `Yes, use detected keys`.
</Step>
<Step title="System Key for Oracle">
**Prompt:**
```terminal wrap theme={null}
Please select an option for the system key for Oracle Bridge Executor
```
**Action:**
Select `Generate new system key`.
</Step>
<Step title="Pre-fill Data">
**Prompt:**
```terminal wrap theme={null}
Existing config.json detected. Would you like to use the data in this file to pre-fill some fields?
```
**Action:**
Select `Yes, prefill`.
</Step>
<Step title="Listen Address">
**Prompt:**
```terminal wrap theme={null}
Specify listen address of the bot
```
**Action:**
Press `Tab` to use `localhost:3000` (ensure nothing else is running on this port).
</Step>
<Step title="Finalize Configuration">
**Action:**
Press `Enter` for L1 RPC, Chain ID, and Gas Denom. For Rollup RPC, press `Tab` to use `http://localhost:26657`.
</Step>
<Step title="Start the Bot">
Once initialized, start the bot in the background:
```bash wrap theme={null}
weave opinit start executor -d
```
</Step>
</Steps>
### 8.2 Start the IBC Relayer
The relayer enables asset transfers (like INIT) between the L1 and your
appchain.
<Warning>Docker Desktop must be running to launch the relayer.</Warning>
**Run the following command:**
```bash wrap theme={null}
weave relayer init
```
Follow the interactive guide:
<Steps>
<Step title="Select Rollup">
**Prompt:**
```terminal wrap theme={null}
Select the type of Interwoven rollup you want to relay
```
**Action:**
Select `Local Rollup (<YOUR_APPCHAIN_ID>)`.
</Step>
<Step title="Endpoints">
**Action:**
Press `Tab` for both **RPC** (`http://localhost:26657`) and **REST** (`http://localhost:1317`) endpoints.
</Step>
<Step title="Channel Method">
**Prompt:**
```terminal wrap theme={null}
Select method to set up IBC channels for the relayer
```
**Action:**
Select `Subscribe to only transfer and nft-transfer IBC Channels (minimal setup)`.
</Step>
<Step title="Select Channels">
**Prompt:**
```terminal wrap theme={null}
Select the IBC channels you would like to relay
```
**Action:**
Press `Space` to select all (transfer and nft-transfer), then press `Enter`.
</Step>
<Step title="Challenger Key">
**Prompt:**
```terminal wrap theme={null}
Do you want to set up relayer with the challenger key
```
**Action:**
Select `Yes (recommended)`.
</Step>
<Step title="Start Relayer">
Start the relayer process:
```bash wrap theme={null}
weave relayer start -d
```
<Note>
You can view relayer logs at any time by running `weave relayer log` in your terminal.
</Note>
</Step>
</Steps>
<Note>
**Persistence After Restart:**
After restarting your computer, the relayer remains managed by Docker. As
long as Docker Desktop is open, it should still be running. You still need to
restart your rollup full node and executor:
```bash wrap theme={null}
weave rollup start -d
weave opinit start executor -d
```
</Note>
## Step 9: Final Key Setup
**Why:** The `Gas Station` account acts as your `Universal Developer
Key`. Importing it allows you to sign transactions manually via the CLI, and it
enables your AI co-pilot to deploy contracts and interact with your appchain.
**Action:** Run these commands to import your account into both the L1
(`initiad`) and L2 (`minitiad`) keychains:
```bash wrap theme={null}
# Extract your mnemonic from the weave config
MNEMONIC=$(jq -r '.common.gas_station.mnemonic' ~/.weave/config.json)
# Import into initiad (L1)
initiad keys add gas-station --recover --keyring-backend test --coin-type 60 --key-type eth_secp256k1 --source <(echo -n "$MNEMONIC")
# Import into minitiad (L2)
minitiad keys add gas-station --recover --keyring-backend test --coin-type 60 --key-type eth_secp256k1 --source <(echo -n "$MNEMONIC")
```
**Action:** Verify the import by listing your keys to ensure `gas-station`
appears in both:
```bash wrap theme={null}
# Verify L1 keys
initiad keys list --keyring-backend test
# Verify L2 keys
minitiad keys list --keyring-backend test
```
<Warning>
**Production Security:** This workflow is for rapid prototyping only.
* **Insecure Storage:** `config.json` and `--keyring-backend test` are for convenience, not production.
* **Mainnet:** Use secure keyrings (OS keychain, hardware wallet) and never store mnemonics in plaintext.
* **Best Practice:** Use separate accounts for `Gas Station`, `Validator`, and `Developer` roles on Mainnet.
</Warning>
## Step 10: Verifying Your Appchain
After completing the infrastructure setup, verify that everything is healthy.
```terminal title="Prompt: Verify my appchain is healthy" wrap theme={null}
Using the `initia-appchain-dev` skill, please verify that my appchain, executor bot, and relayer are running and that my Gas Station account has a balance.
```
## Step 11: Build Your App
Congratulations! You have successfully launched your first appchain. Next, head
to the [Builder Guide](/hackathon/builder-guide) to select whether to build
from scratch or start from a Blueprint, then build your app with AI, debug
issues, and prepare your submission.
# Lotteria
Source: https://docs.initia.xyz/hackathon/lotteria
This guide walks through building **[Lotteria](https://lotteria-five.vercel.app/)**, an onchain lottery machine, as
a working example of how to build a full-stack appchain on Initia. It covers
writing Move modules, connecting a frontend with InterwovenKit, and deploying to
your rollup.
The full source code is available in the
[Lotteria reference repository](https://github.com/yonnie-park/lotteria).
This is a demo repository built as a reference for hackathon participants. If
you get stuck on any step, from writing Move modules to wiring up your frontend,
use the reference implementation as a working example to compare against.
# Prerequisites
Before you begin, make sure you have completed the
[Set Up Your Appchain](/hackathon/get-started) setup, including:
* A running appchain via `weave init`
* `initiad` and `minitiad` installed and in your PATH. This should already be installed when you set up your appchain
* OPinit Executor and IBC Relayer running connected to your appchain
* A funded Weave Gas Station account imported into your local keyring
### Project Structure
```text theme={null}
lotteria/
├── move/ # Move smart contract modules
├── frontend/ # React frontend application
├── interwovenkit # InterwovenKit submodule
└── package.json
```
# 1. Move Modules
Move is the smart contract language for the MoveVM track on Initia. In
Lotteria, the Move module handles all the core lottery logic: creating rounds,
buying tickets, drawing winners, and distributing prizes.
### Setting Up the Move Package
Create a `move/` directory in your project root with the following structure:
```
move/
├── sources/
│ ├── lottery.move
│ └── lottery_random.move
└── Move.toml
```
<Note>
The lottery module depends on a helper module `lottery_random` for onchain randomness (winner
selection). Both source files are required for compilation. Copy both from the
[reference repo](https://github.com/yonnie-park/lotteria/tree/main/move/sources).
</Note>
Your `Move.toml` defines the package metadata, dependencies, and the address
your module will be published under. You need to convert your Initia address to
its hex representation:
```bash theme={null}
initiad keys parse <YOUR_INIT_ADDRESS>
# Output: bytes: <YOUR_HEX_ADDRESS>
```
Then configure `Move.toml`:
```toml title="move/Move.toml" theme={null}
[package]
name = "lotteria"
version = "0.0.0"
[dependencies]
InitiaStdlib = { git = "https://github.com/initia-labs/movevm.git", subdir = "precompile/modules/initia_stdlib", rev = "main" }
[addresses]
lottery = "<YOUR_HEX_ADDRESS>"
std = "0x1"
initia_std = "0x1"
```
The `InitiaStdlib` dependency gives you access to core modules like `coin`,
`signer`, `event`, and `object`, which are essential building blocks for any
onchain application.
### Writing the Lottery Module
The lottery module manages the full lifecycle of a lottery round. Here is a
breakdown of the key components.
**Module declaration and imports:**
```move theme={null}
module lottery::lottery {
use std::signer;
use std::vector;
use std::error;
use lottery::lottery_random;
use initia_std::fungible_asset::Metadata;
use initia_std::object::{Self, ExtendRef};
use initia_std::primary_fungible_store;
use initia_std::block;
use initia_std::table::{Self, Table};
}
```
**Data structures:**
Define the resources that will live onchain. A lottery needs to track the
current round state, ticket purchases, and prize pool:
```move theme={null}
struct LotteryConfig has key {
admin: address,
current_draw_id: u64,
ticket_price: u64,
total_tickets_sold: u64,
extend_ref: ExtendRef,
vault_addr: address,
}
```
The `has key` ability means this struct can be stored as a top-level resource in
global storage, which is how Move manages persistent onchain state.
**Core entry functions:**
Entry functions are the public interface that users and frontends call via
transactions:
* `initialize`: Creates the initial lottery config and first draw
* `buy_ticket`: Validates six picked numbers and transfers the ticket price
* `execute_draw`: Generates winning numbers for a draw
* `finalize_draw`: Calculates prize amounts per winner tier
* `get_ticket_price`: A view function that returns the configured ticket price
without modifying state
```move theme={null}
public entry fun buy_ticket(
buyer: &signer,
numbers: vector<u8>,
) acquires LotteryConfig, DrawStore, TicketCollection {
let buyer_addr = signer::address_of(buyer);
assert!(vector::length(&numbers) == NUMBERS_TO_PICK, error::invalid_argument(EINVALID_NUMBERS));
validate_numbers(&numbers);
let config = borrow_global_mut<LotteryConfig>(@lottery);
let draw_store = borrow_global_mut<DrawStore>(@lottery);
let metadata = object::address_to_object<Metadata>(@0x9759eac00e068b4e8adc206d17c6a8477f00ae41f824f0e2e81b3832cc8065ae);
primary_fungible_store::transfer(buyer, metadata, config.vault_addr, config.ticket_price);
let (_, current_time) = block::get_block_info();
let draw_id = config.current_draw_id;
let ticket_entry = TicketEntry { owner: buyer_addr, numbers };
let draw_ticket_list = table::borrow_mut(&mut draw_store.draw_tickets, draw_id);
vector::push_back(draw_ticket_list, ticket_entry);
}
```
<Warning>
**Replace the Reference Metadata Address:** The `Metadata` object address in `lottery.move` is specific to the token used by the reference deployment and
will not exist on your local rollup. Before building, query the metadata object for the token you want to use
for ticket payments:
```bash theme={null}
minitiad query move metadata --denom <YOUR_FEE_DENOM> --node http://localhost:26657
# metadata: 0x...
```
Replace every hardcoded `object::address_to_object<Metadata>(@0x...)` occurrence in `lottery.move` with the
returned metadata address.
</Warning>
**View functions:**
View functions let the frontend query onchain state without submitting a
transaction:
```move theme={null}
#[view]
public fun get_ticket_price(): u64 {
TICKET_PRICE
}
```
### Building and Deploying the Module
Build the module to check for compilation errors:
```bash theme={null}
initiad move build --path ./move
```
Deploy to your running appchain:
```bash theme={null}
export MODULE_OWNER=gas-station # or your key name
export L2_CHAIN_ID=<YOUR_CHAIN_ID>
export FEE_DENOM=umin # replace with your rollup's configured fee token denom
minitiad move deploy \
--path ./move \
--upgrade-policy COMPATIBLE \
--from $MODULE_OWNER \
--keyring-backend test \
--gas auto --gas-adjustment 1.5 \
--gas-prices 0.15$FEE_DENOM \
--node http://localhost:26657 \
--chain-id $L2_CHAIN_ID \
--yes
```
Use `minitiad` (not `initiad`) here because you are deploying to your Layer 2
rollup, not the Initia L1.
<Note>
The fee denom (`umin` above) depends on the fee token you configured during `weave init`. To
confirm the correct denom for your rollup, run:
```bash theme={null}
minitiad query bank total --node http://localhost:26657
```
and use the denom shown for your rollup's native token.
</Note>
To verify the deployment, query a view function:
```bash theme={null}
export MODULE_ADDRESS=<YOUR_HEX_ADDRESS>
minitiad query move view $MODULE_ADDRESS lottery get_ticket_price \
--args '[]' \
--node http://localhost:26657
```
<Warning>
**Required Empty Args:** Even for view functions that take no arguments, `--args '[]'` is required. Omitting it will
cause a CLI parse error.
</Warning>
To execute a function, for example to initialize the module state after deployment:
```bash theme={null}
minitiad tx move execute $MODULE_ADDRESS lottery initialize \
--from $MODULE_OWNER \
--keyring-backend test \
--gas auto --gas-adjustment 1.5 \
--gas-prices 0.15$FEE_DENOM \
--node http://localhost:26657 \
--chain-id $L2_CHAIN_ID \
--yes
```
# 2. Using InterwovenKit
[InterwovenKit](https://github.com/initia-labs/interwovenkit) is a React
library that provides components and hooks for connecting dApps to Initia and
Interwoven Rollups. It handles wallet connections, transaction signing, and
chain interactions out of the box.
### Installation
Install the InterwovenKit React package:
```bash theme={null}
npm install @initia/interwovenkit-react
```
If you are starting from scratch, scaffold a new React project with Vite:
```bash theme={null}
npm create vite@latest frontend -- --template react-ts
cd frontend
npm install
npm install @initia/interwovenkit-react
```
### Setting Up the Provider
Wrap your application with `InterwovenKitProvider`. This is the top-level
context that makes wallet state and transaction methods available throughout
your component tree.
In your `main.tsx` or `App.tsx`:
```tsx theme={null}
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { createConfig, http, WagmiProvider } from "wagmi"
import { mainnet } from "wagmi/chains"
import {
InterwovenKitProvider,
TESTNET,
injectStyles,
} from "@initia/interwovenkit-react"
import InterwovenKitStyles from "@initia/interwovenkit-react/styles.js"
const qu프로젝트로 돌아가기