Prerequisites
Before you begin, make sure you have completed the Set Up Your Appchain setup, including:- A running appchain via
weave init initiadandminitiadinstalled 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
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 amove/ directory in your project root with the following structure:
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.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:
Move.toml:
move/Move.toml
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: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 drawbuy_ticket: Validates six picked numbers and transfers the ticket priceexecute_draw: Generates winning numbers for a drawfinalize_draw: Calculates prize amounts per winner tierget_ticket_price: A view function that returns the configured ticket price without modifying state
Building and Deploying the Module
Build the module to check for compilation errors:minitiad (not initiad) here because you are deploying to your Layer 2
rollup, not the Initia L1.
The fee denom (and use the denom shown for your rollup’s native token.
umin above) depends on the fee token you configured during weave init. To
confirm the correct denom for your rollup, run:2. Using InterwovenKit
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:Setting Up the Provider
Wrap your application withInterwovenKitProvider. 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:
Connecting a Wallet
TheuseInterwovenKit hook provides everything you need for wallet connection.
Here is a simplified wallet connection component based on the wallet controls in Lotteria’s
Header.tsx:
openConnect to launch the wallet connection drawer. Once connected, it
displays the user’s Initia username (if they have one) or a truncated version
of their address. Clicking the button calls openWallet to open the wallet
detail panel.
Depositing Assets
Users need tokens on your appchain to interact with it. InterwovenKit provides a built-in deposit flow that handles cross-chain bridging. Here is theopenDeposit pattern used by Lotteria:
openDeposit method opens a drawer that lets users bridge tokens from
Initia L1 (or other connected chains) to your appchain. The denoms array
specifies which token denominations are accepted. The chainId should match
your appchain’s chain ID.
The component only renders when a wallet is connected (address is truthy),
since depositing requires an active wallet session.
Sending Transactions
To interact with your Move module from the frontend, userequestTxSync to
construct and send transactions:
requestTxSync method prompts the user’s wallet to sign and broadcast the
transaction. It returns the transaction hash on success.
Querying Onchain State
To query and read data using the view functions of your Move module, you can utilize the chain’s REST endpoint as follows:3. Connecting to the Chain
Chain Configuration
Your appchain runs locally afterweave init. The default endpoints are:
These endpoints are what your frontend uses to query state and broadcast
transactions.
Bridging Assets via IBC
Once the IBC Relayer is running (see Set Up Your Appchain), you can bridge INIT tokens from the L1 testnet to your appchain. This is how users fund their accounts on your rollup. The bridge flow works through IBC transfer channels that the relayer establishes between Initia L1 and your rollup. Users can send tokens from L1 to your chain, and the tokens arrive as IBC-denominated assets.Frontend Development Workflow
A practical development loop looks like this:- Write or update your Move module in
move/sources/ - Build and deploy with
minitiad move deploy - Test the module via CLI with
minitiad tx move executeandminitiad query move view - Build your frontend components using InterwovenKit hooks
- Run the frontend dev server and test end-to-end
Summary
Building an appchain on Initia with the Move track involves three layers:- Move modules define your onchain logic. Write your structs and entry
functions, build with
initiad move build, and deploy withminitiad move deploy. - InterwovenKit connects your React frontend to the chain. Wrap your app
in
InterwovenKitProvider, useuseInterwovenKitfor wallet connection andrequestTxSyncfor transactions. - Chain connectivity is handled by the Interwoven Stack. Your local rollup exposes RPC and REST endpoints, and the IBC Relayer enables cross-chain token transfers.