Building your first Micro-rollup
Bootstrapping a new project
To create a new project, run the following command:
npx @stackr/cli@latest init- Choose a template from the list and follow the instructions.
_ _ _ _
___| |_ __ _ ___| | ___ __ ___| (_)
/ __| __/ _` |/ __| |/ / '__| _____ / __| | |
\__ \ || (_| | (__| <| | |_____| | (__| | |
|___/\__\__,_|\___|_|\_\_| \___|_|_|
? Pick a template (Use arrow keys)
❯ Counter (Recommended)
Chess
Token Transfer
Bridge
EmptyFor the purpose of this tutorial, we will use the Counter template.
- After this you'll be asked to enter a "Project Name", enter a name and press enter.
- You'll be asked to pick the Database after this, based on the Database you choose, we set up the project for you. For this tutorial, we will use
SQLite. You can choose any database you want. For any other database, you'll have to manually change the database configuration in thestackr.config.tsfile.
? Database Driver (Use arrow keys)
❯ SQLite (Recommended)
PostgreSQL
MySQL
MariaDB- You'll see some green checkmarks at this point and instructions to follow. Follow the instructions and you'll have a new project created.
✔ ⚙️ Set up MRU
✔ 🧹 Set up git
✔ ⬇️ Installed packages
Get started by running the following commands:
1. cd uno/
2. cp .env.example .env & modify values
3. Register your rollup using npx @stackr/cli@latest register
Setting up your config
Setup .env
- Let's
cdinto the project directory and first copy the.env.examplefile to.env. - Update the following values in the
.envfile.- You can get the latest values listed in the Providers and RPCs page.
PRIVATE_KEY=<PRIVATE_KEY>
REGISTRY_CONTRACT=<REGISTRY_CONTRACT>
VULCAN_RPC=<VULCAN_RPC>
L1_RPC=<L1_RPC>
DATABASE_URI=<DATABASE_URI>Setup stackr.config.ts
Now let's dive into the stackr.config.ts file.
- By default, the micro-rollup is configured to run in Sandbox mode (
isSandbox). This is explained in the next section. - The main properties you might wish to tune here are
blockSizeandblockTimeof your micro-rollup. You can also setallowEmptyBlockstotrueif you want your micro-rollup to always produce blocks everyblockTimemilliseconds (even when there are no actions).stackr.config.tssequencer: { blockSize: 16, blockTime: 10, allowEmptyBlocks: true } - The
domainin the config is used to create EIP-712 Typed Signature over the inputs of actions. Feel free to tune this as per your requirements.stackr.config.tsdomain: { name: "<APP_NAME>", version: "<APP_VERSION>", salt: "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" } - You can refer to Stackr Config section for the explanation of every available configuration property.
Project Structure
- The
srcdirectory contains the code for your application. - The
src/stackrdirectory contains the code for the State Machines and State Transition Functions.
We don't enforce any specific restrictions on the naming of the files, but keeping files related to the State Machines and STF in the src/stackr directory is recommended.
├── src
│ ├── stackr
│ │ ├── machine.ts
│ │ ├── schemas.ts
│ │ ├── transitions.ts
│ │ └── hooks.ts
│ ├── index.ts
│ ├── stackr.config.ts
│ └── deployment.json-
machine.tscontains theStateMachineandStateclasses for your application.- Please make sure to export the
StateMachineobject from this file in one of the following ways:
machine.ts (declaration export)export const myMachine = new StateMachine({ ... }); - Please make sure to export the
-
schemas.tscontains the Action Schemas for your application. -
transitions.tscontains the State Transition Functions (STF) for your application. -
hooks.tscontains the Block Hooks for your application, if any.
Next Steps
In this section, we covered how to create and setup a new project using Stackr CLI and SDK. In the next section, we will see how to run our micro-rollup and interact with it.