Create A Sui Dapp

To begin, open a terminal or console at the location you plan to store your dapp. Use the pnpm create dubhe command to create an sui dapp by dubhe with the name 101:

pnpm create dubhe

create-dapp

Running the previous command creates a directory with the name you provide (101 in this case). The command populates the new directory with a skeleton Move project that consists of a sources directory and a Move.toml manifest file. Open the manifest with a text editor to review its contents:

[package]
name = "counter"
version = "1.0.0"
edition = "2024"
 
[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.38.3" }
Dubhe = { local = "../dubhe-framework" }
 
[addresses]
sui = "0x2"
counter = "0x0"

The manifest file contents include available sections of the manifest and comments that provide additional information. In Move, you prepend the hash mark (#) to a line to denote a comment.

  • [package]: Contains metadata for the package. By default, the sui move new command populates only the name value of the metadata. In this case, the example passes my_first_package to the command, which becomes the name of the package. You can delete the first # of subsequent lines of the [package] section to provide values for the other available metadata fields.
  • [dependencies]: Lists the other packages that your package depends on to run. By default, the sui move new command lists the Sui package on GitHub (Testnet version) as the lone dependency.
  • [addresses]: Declares named addresses that your package uses. By default, the section includes the package you create with the sui move new command and an address of 0x0. This value can be left as-is and indicates that package addresses are automatically managed when published and upgraded.

Defining the Dubhe Config

import { DubheConfig } from "@0xobelisk/sui-common";
 
export const dubheConfig = {
  name: "counter",
  description: "counter contract",
  schemas: {
    counter: {
      structure: {
        value: "StorageValue<u32>",
      },
      events: [
        {
          name: "Increment",
          fields: {
            value: "u32",
          },
        },
      ],
      errors: [
        {
          name: "InvalidIncrement",
          message: "Number can't be incremented, must be more than 0",
        },
      ],
    },
  },
} as DubheConfig;
  • [name]: Project name, this configuration attribute determines the name of the package to be generated via the CLI.
  • [description]: Project description, this configuration property determines the description of the project that can be populated in move.toml.
  • [schemas]: Data model, this configuration attribute determines the project’s ability to generate Move data contracts that are structured and stored in the Sui chain.
pnpm run schema:gen

The generated project structure looks like this:

contracts/counter
β”œβ”€β”€ Move.toml
└── sources
    β”œβ”€β”€ codegen
    β”‚   β”œβ”€β”€ errors
    β”‚   β”‚   └── counter_error_invalid_increment.move
    β”‚   β”œβ”€β”€ events
    β”‚   β”‚   └── counter_event_increment.move
    β”‚   └── schemas
    β”‚       β”œβ”€β”€ counter.move
    β”‚       └── default
    β”‚           └── dapp
    β”‚               β”œβ”€β”€ metadata.move
    β”‚               β”œβ”€β”€ schema.move
    β”‚               └── system.move
    β”œβ”€β”€ scripts
    β”‚   β”œβ”€β”€ deploy_hook.move
    β”‚   └── migrate.move
    β”œβ”€β”€ systems
    β”‚
    └── tests
        β”œβ”€β”€ counter.move
        └── init.move