### Download and Setup Simple Blog Example Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Download the Rooch network source code archive, extract it, and change the directory to the simple blog example. This allows direct interaction with the blog contract functions. ```shell wget https://github.com/rooch-network/rooch/archive/refs/heads/main.zip unzip main.zip cd rooch-main/examples/simple_blog ``` -------------------------------- ### Setup Move Development Environment Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/documentation/book/translations/move-book-zh/src/move-tutorial.md Executes the `dev_setup.sh` script to install all of Move's dependencies and configure the development environment. The script automatically handles dependency installation and environment variable setup. ```bash cd move ./scripts/dev_setup.sh -ypt ``` -------------------------------- ### Rooch Server Startup Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.zh-CN.mdx Starts the Rooch server, which provides the necessary infrastructure for handling and responding to smart contract behaviors. This command initiates the local Rooch container service. ```shell rooch server start ``` -------------------------------- ### Download Rooch Binary Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Downloads the latest prebuilt binary tarball for Rooch, specifically for Ubuntu in this example. Ensure you select the version appropriate for your operating system. ```shell wget https://github.com/rooch-network/rooch/releases/latest/download/rooch-ubuntu-latest.zip ``` -------------------------------- ### Run Rooch Binary Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Navigates into the directory containing the extracted Rooch files and executes the Rooch binary. This is a test to confirm the installation. ```shell cd rooch-artifacts ./rooch ``` -------------------------------- ### Start Rooch Server Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Command to start the local Rooch server, which manages contract execution and responds to RPC requests. ```shell rooch server start ``` -------------------------------- ### Setup Move Development Environment Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/documentation/tutorial/README.md Navigates into the cloned Move directory and executes the setup script to install dependencies and configure the environment. The `-ypt` flags typically mean yes to all prompts, build, and test. ```bash cd move ./scripts/dev_setup.sh -ypt ``` -------------------------------- ### Compile and Install Rooch from Source (Ubuntu) Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/installation.en-US.mdx Navigates into the cloned Rooch directory, compiles the project using Cargo, and copies the resulting binary to the Cargo bin directory for system-wide access. ```shell cd rooch && cargo build && cp target/debug/rooch ~/.cargo/bin/ ``` -------------------------------- ### Deploy Example Contract Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/connect-to-rooch/connect-testnet.zh-CN.mdx Steps to clone the Rooch repository, navigate into the project directory, and publish an example smart contract using the `rooch move publish` command. This requires obtaining Rooch Gas Coin beforehand. ```bash git clone https://github.com/rooch-network/rooch.git ``` ```bash cd rooch ``` ```bash rooch move publish -p ./examples/quick_start_counter/ --sender-account default --named-addresses quick_start_counter=default ``` -------------------------------- ### Rooch MyBlog Resource Output Example Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Example JSON output from querying a 'MyBlog' resource. It shows the resource's value, type, and decoded content, including a list of article IDs and the blog's name. ```json [ { "value": "0x0a526f6f636820626c6f670101f3264835925cf7573b0da6a5e8b97d6051b695455b012c1d87482b6652892379", "value_type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog", "decoded_value": { "abilities": 12, "type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog", "value": { "articles": ["0xf3264835925cf7573b0da6a5e8b97d6051b695455b012c1d87482b6652892379"], "name": "Rooch blog" } }, "display_fields": null } ] ``` -------------------------------- ### Setup Development Environment Source: https://github.com/rooch-network/rooch/blob/main/sdk/typescript/bitseed-sdk/README.md Steps to clone the Bitseed SDK repository and install its dependencies for local development. This includes cloning the repository, navigating to the SDK directory, and installing npm packages. ```bash git clone https://github.com/bitseed/bitseed.git cd sdk/bitseed-sdk npm install ``` -------------------------------- ### Verify Rooch Installation Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.zh-CN.mdx Navigates into the extracted directory and executes the 'rooch' binary to confirm it's installed correctly and displays the usage information. ```shell cd rooch-artifacts ./rooch ``` -------------------------------- ### Move Project Configuration (Move.toml) Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.zh-CN.mdx An example of a 'Move.toml' file generated for a new Rooch project. It defines package metadata, project dependencies (MoveStdlib, MoveosStdlib, RoochFramework), and address mappings. ```toml [package] name = "simple_blog" version = "0.0.1" [dependencies] MoveStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/move-stdlib", rev = "main" } MoveosStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/moveos-stdlib", rev = "main" } RoochFramework = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/rooch-framework", rev = "main" } [addresses] simple_blog = "_" std = "0x1" moveos_std = "0x2" rooch_framework = "0x3" ``` -------------------------------- ### Rooch CLI Commands for Quick Start Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/counter.en-US.mdx Demonstrates essential Rooch CLI commands for building, publishing, querying resources, and executing Move functions in a quick start scenario. These commands are crucial for deploying and interacting with Move modules on the Rooch network. ```shell $ rooch move build --named-addresses quick_start_counter=default $ rooch move publish --named-addresses quick_start_counter=default # 注意 `0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81` 是我演示的地址,当你实际运行时,需要更改为你自己的钱包地址 $ rooch resource --address 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81 --resource 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81::quick_start_counter::Counter $ rooch move run --function 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81::quick_start_counter::increase --sender-account default $ rooch resource --address 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81 --resource 0xc4a286bef174e126ef24363a0799c069504d0f132f713bf4762ad127c799df81::quick_start_counter::Counter ``` -------------------------------- ### Move.toml Configuration for Development Addresses Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/move-examples.en-US.mdx Provides an example of the `Move.toml` file structure, specifically showing the `[dev-addresses]` table required for unit testing and resolving package dependencies. ```move # Example Move.toml snippet [package] name = "quick_start_counter" version = "0.1.0" [addresses] # Std = "0x1" [dev-addresses] # quick_start_counter = "0x0" # Example address for development ``` -------------------------------- ### Compile and Install Rooch from Source (Windows) Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/installation.en-US.mdx Compiles the Rooch project using Cargo and copies the executable to the Cargo bin directory. This makes the Rooch binary accessible from the command line. ```shell cd rooch cargo build cp target/debug/rooch.exe ~/.cargo/bin/ ``` -------------------------------- ### Start Rooch Local Server Source: https://github.com/rooch-network/rooch/blob/main/examples/counter/readme.md Starts a local Rooch network server. Ensure the ROOCH_CONFIG environment variable is set to point to your configuration file before execution. ```shell rooch server start ``` -------------------------------- ### Install Rooch Binary (Linux) Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/installation.en-US.mdx Downloads the latest Rooch binary for Ubuntu, decompresses the archive, and copies the executable to the system's standard binary directory for execution. ```shell wget https://github.com/rooch-network/rooch/releases/latest/download/rooch-ubuntu-latest.zip unzip rooch-ubuntu-latest.zip sudo cp rooch /usr/local/bin ``` -------------------------------- ### Install Rust on Windows Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/installation.en-US.mdx Downloads and installs the Rust toolchain for Windows. This executable sets up the necessary environment for Rust development on the Windows platform. ```shell https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/rooch-network/rooch/blob/main/examples/rooch_fish/web/README.md Installs all necessary packages for the frontend development environment. This command is essential before starting the development server or building the project. ```bash npm install ``` -------------------------------- ### Start Rooch Local Server Source: https://github.com/rooch-network/rooch/blob/main/examples/view_function_loop/readme.md Starts a local Rooch network server. This command initializes and runs the necessary services for local development and testing. Ensure the ROOCH_CONFIG environment variable is set correctly before execution. ```rooch-cli rooch server start ``` -------------------------------- ### Download Rooch Binary Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.zh-CN.mdx Downloads the latest pre-built binary for the Rooch network. Ensure you select the correct version for your operating system. ```shell wget https://github.com/rooch-network/rooch/releases/latest/download/rooch-ubuntu-latest.zip ``` -------------------------------- ### Prover Configuration File Example Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/move-prover/doc/user/prover-guide.md Defines prover behavior using a TOML configuration file named Prover.toml. This example shows how to enable tracing by default for all functions within a package. ```toml [prover] auto_trace_level = "VerifiedFunction" ``` -------------------------------- ### Example: Use Current Session Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/sdk/wallet-integrate.en-US.mdx Illustrates how to import and use the `useCurrentSession` hook from the `@roochnetwork/rooch-sdk-kit` package to get the active session key. ```ts import { useCurrentSession } from '@roochnetwork/rooch-sdk-kit'; const sessionKey = useCurrentSession(); ``` -------------------------------- ### Deploy Example Contract Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/connect-to-rooch/connect-testnet.en-US.mdx Clones the Rooch repository, navigates into it, and publishes an example contract ('quick_start_counter') to the testnet. Requires obtaining Rooch Gas Coin beforehand. ```bash git clone https://github.com/rooch-network/rooch.git cd rooch rooch move publish -p ./examples/quick_start_counter/ --sender-account default --named-addresses quick_start_counter=default ``` -------------------------------- ### Rooch State Query Output Example Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Example JSON output from querying an object's state using the Rooch CLI. It details the object's value, type, and decoded content, including article title and body. ```json [ { "value": "0x01f3264835925cf7573b0da6a5e8b97d6051b695455b012c1d87482b6652892379ff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7005350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000000000000000000000000000000000000b48656c6c6f20526f6f636833416363656c65726174696e6720576f726c642773205472616e736974696f6e20746f20446563656e7472616c697a6174696f6e", "value_type": "0x2::object::ObjectEntity<0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_article::Article>", "decoded_value": { "abilities": 0, "type": "0x2::object::ObjectEntity<0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_article::Article>", "value": { "flag": 0, "id": "0xf3264835925cf7573b0da6a5e8b97d6051b695455b012c1d87482b6652892379", "owner": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7", "size": "0", "state_root": "0x5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000000000000000000000000000000000000b48656c6c6f20526f6f636833416363656c65726174696e6720576f726c642773205472616e736974696f6e20746f20446563656e7472616c697a6174696f6e", "value": { "abilities": 12, "type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_article::Article", "value": { "body": "Unlocking infinite utility for the Bitcoin Economy", "title": "Hello Rooch", "version": "0" } } } }, "display_fields": null } ] ``` -------------------------------- ### Rooch State Query Result Example Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Example JSON output from querying the state of a Move contract resource. It shows the resource's value, type, and decoded value, including contract-specific fields like 'name' and 'articles'. ```json [ { "value": "0x064d79426c6f6700", "value_type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog", "decoded_value": { "abilities": 12, "type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog", "value": { "articles": [], "name": "MyBlog" } }, "display_fields": null } ] ``` ```json [ { "value": "0x0a526f6f636820626c6f6700", "value_type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog", "decoded_value": { "abilities": 12, "type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog", "value": { "articles": [], "name": "Rooch blog" } }, "display_fields": null } ] ``` -------------------------------- ### Run the Rooch dApp Locally Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/first-dapp.en-US.mdx Starts the local development server for the dApp, typically using Bun. This command makes the dApp accessible via a local preview link. ```bash bun dev ``` -------------------------------- ### Rooch Build Success Output Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Example output indicating a successful compilation of a Move contract, showing dependencies being included and the target module being built. ```shell INCLUDING DEPENDENCY MoveStdlib INCLUDING DEPENDENCY MoveosStdlib INCLUDING DEPENDENCY RoochFramework BUILDING simple_blog Success ``` -------------------------------- ### Rooch Server Listening Information Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Log messages indicating the Rooch server has started successfully and is listening on a specific address and port for JSON-RPC requests. ```shell 2023-07-03T15:44:33.315228Z INFO rooch_rpc_server: JSON-RPC HTTP Server start listening 0.0.0.0:6767 2023-07-03T15:44:33.315256Z INFO rooch_rpc_server: Available JSON-RPC methods : ["wallet_accounts", "eth_blockNumber", "eth_getBalance", "eth_gasPrice", "net_version", "eth_getTransactionCount", "eth_sendTransaction", "rooch_sendRawTransaction", "rooch_getAnnotatedStates", "eth_sendRawTransaction", "rooch_getTransactions", "rooch_executeRawTransaction", "rooch_getEventsByEventHandle", "rooch_getTransactionByHash", "rooch_executeViewFunction", "eth_getBlockByNumber", "rooch_getEvents", "eth_feeHistory", "eth_getTransactionByHash", "eth_getBlockByHash", "eth_getTransactionReceipt", "rooch_getTransactionInfosByOrder", "eth_estimateGas", "eth_chainId", "rooch_getTransactionInfosByHash", "wallet_sign", "rooch_getStates"] ``` -------------------------------- ### Rooch CLI Usage Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Displays the help information for the Rooch command-line interface, listing available commands such as 'account', 'init', 'move', 'server', and options like '--help' and '--version'. ```shell Usage: rooch Commands: account Tool for interacting with accounts init Tool for init with rooch move CLI frontend for the Move compiler and VM server Start Rooch network state Get states by accessPath object Get object by object id resource Get account resource by tag transaction Tool for interacting with transaction event Tool for interacting with event abi env Interface for managing multiple environments session-key Session key Commands rpc help Print this message or the help of the given subcommand(s) Options: -h, --help Print help -V, --version Print version ``` -------------------------------- ### Move Contract Publish Execution Status Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Example JSON output confirming the successful execution of a contract publish operation, specifically highlighting the 'executed' status. ```json { "//": "... other fields ...", "execution_info": { "//": "... other fields ...", "status": { "type": "executed" } }, "//": "... other fields ..." } ``` -------------------------------- ### Query Resource State Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Uses the Rooch CLI to query the state of a specific resource associated with an account. This example retrieves the 'MyBlog' resource, showing stored articles. ```shell rooch state --access-path /resource/0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7/0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog ``` -------------------------------- ### Rooch Dev Setup Script Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/documentation/book/translations/move-book-zh/src/move-tutorial.md Provides a bash script command to set up development dependencies for the Rooch project, specifically for Move development. It includes flags for installing specific components and requires sourcing the profile to update the environment. ```bash # run the following in move repo root directory ./scripts/dev_setup.sh -yp source ~/.profile ``` -------------------------------- ### Move Contract Function Definition Example Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Illustrates a typical function definition within a Move smart contract, including the use of entry functions callable from the command line. ```move delete_article_from_myblog(owner, article_id); let article_obj = object::take_object(owner, article_id); simple_article::delete_article(article_obj); } } ``` -------------------------------- ### Create and Navigate Project Directory Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/sdk/typescript-sdk/ts-sdk-quick-start.en-US.mdx Creates a new directory for the Rooch project and navigates into it. This is the initial step for setting up a new Rooch application. ```bash mkdir sdk-quick-start cd sdk-quick-start ``` -------------------------------- ### Example: Get Rooch Balances Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/sdk/wallet-integrate.en-US.mdx Demonstrates how to use the `useRoochClientQuery` hook to call the `getBalances` RPC method. It fetches asset lists for a given owner address with optional refetch intervals. ```tsx const { data: assetsList, isPending, refetch: refetchAssetsList } = useRoochClientQuery( 'getBalances', { owner: BitcoinAddressToRoochAddress(address).toHexAddress(), }, { refetchInterval: 5000 } ); ``` -------------------------------- ### Rooch Network Dev Setup Script Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/documentation/tutorial/README.md Provides bash commands to set up development environment dependencies for the Rooch network, specifically for running Move prover tools like Boogie. It involves running a setup script and sourcing the profile. ```bash # run the following in move repo root directory ./scripts/dev_setup.sh -yp source ~/.profile ``` -------------------------------- ### Rooch DID CLI Usage Examples Source: https://github.com/rooch-network/rooch/blob/main/docs/dev-guide/did_guide.md Practical examples demonstrating how to use the Rooch DID commands for common operations like creating, querying, and managing DIDs. ```shell # Create a personal DID (assuming the current wallet account public key is known or passed as a parameter) rooch did create self --account-public-key z # Query the newly created DID (assuming address is rooch1example...) rooch did query address rooch1example... # Add an Ed25519 verification method for authentication and assertion rooch did manage add-vm --fragment key-ed25519 --method-type Ed25519VerificationKey2020 --public-key z --relationships auth,assert # Generate Ed25519 keys for CADOP rooch did keygen ed25519 # (Assume output user_did_key: did:key:zUserKey...) # Use another account as custodian for CADOP creation rooch did create cadop --user-did-key did:key:zUserKey... --custodian-service-key zServiceKey... --custodian-key-type Ed25519VerificationKey2020 --sender ``` -------------------------------- ### Rooch State Query Output for Article Object Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.zh-CN.mdx Example JSON output from querying an article object's state using the Rooch CLI. It details the object's value, type, and decoded content including title and body. ```json [ { "value": "0x01f3264835925cf7573b0da6a5e8b97d6051b695455b012c1d87482b6652892379ff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7005350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000000000000000000000000000000000000b48656c6c6f20526f6f636833416363656c65726174696e6720576f726c642773205472616e736974696f6e20746f20446563656e7472616c697a6174696f6e", "value_type": "0x2::object::ObjectEntity<0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_article::Article>", "decoded_value": { "abilities": 0, "type": "0x2::object::ObjectEntity<0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_article::Article>", "value": { "flag": 0, "id": "0xf3264835925cf7573b0da6a5e8b97d6051b695455b012c1d87482b6652892379", "owner": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7", "size": "0", "state_root": "0x5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000", "value": { "abilities": 12, "type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_article::Article", "value": { "body": "Unlocking infinite utility for the Bitcoin Economy", "title": "Hello Rooch", "version": "0" } } } }, "display_fields": null } ] ``` -------------------------------- ### Deploy Example Contract Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/connect-to-rooch/connect-devnet.en-US.mdx Clones the Rooch repository, navigates into the directory, and publishes an example contract located in the './examples/counter' path. It specifies the sender account and maps a named address. ```bash git clone https://github.com/rooch-network/rooch.git cd rooch rooch move publish -p ./examples/counter --sender-account default --named-addresses rooch_examples=default ``` -------------------------------- ### Install Rust on Ubuntu Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/installation.en-US.mdx Installs the Rust programming language toolchain using the official rustup script. This is a prerequisite for compiling Rooch from source. ```shell curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Blog Creation and Initialization in Move Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx Provides functions for creating a `MyBlog` resource and initializing it when the module is published. The `init` function automatically creates a blog for the module publisher. ```move /// This init function is called when the module is published /// The owner is the address of the account that publishes the module fun init(owner: &signer) { // auto create blog for module publisher create_blog(owner); } public fun create_blog(owner: &signer) { let articles = vector::empty(); let myblog = MyBlog { name: string::utf8(b"MyBlog"), articles, }; account::move_resource_to(owner, myblog); } ``` -------------------------------- ### Rooch State Query Output for MyBlog Resource Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.zh-CN.mdx Example JSON output from querying the 'MyBlog' resource state using the Rooch CLI. It shows the resource's value, type, and decoded content, including the list of article IDs and the blog name. ```json [ { "value": "0x0a526f6f636820626c6f670101f3264835925cf7573b0da6a5e8b97d6051b695455b012c1d87482b6652892379", "value_type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog", "decoded_value": { "abilities": 12, "type": "0xff795489ecdf184de120244354a3bcf7471cd7683780cb6f19b2336b2ca239b7::simple_blog::MyBlog", "value": { "articles": ["0xf3264835925cf7573b0da6a5e8b97d6051b695455b012c1d87482b6652892379"], "name": "Rooch blog" } }, "display_fields": null } ] ``` -------------------------------- ### Install dApp Dependencies Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/first-dapp.en-US.mdx Installs the necessary project dependencies for the dApp using either Bun or Yarn package managers. ```bash cd my-first-rooch-dapp bun install ``` ```bash cd my-first-rooch-dapp yarn install ``` -------------------------------- ### Install Ubuntu Dependencies Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/getting-started/installation.en-US.mdx Installs essential system dependencies required for compiling the Rooch network on Ubuntu. This includes build tools, Rust prerequisites, and development libraries. ```shell sudo apt install git curl cmake make gcc lld pkg-config libssl-dev libclang-dev libsqlite3-dev g++ protobuf-compiler ``` -------------------------------- ### Get Event Handle GUID in Rooch Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/move-stdlib/nursery/docs/event.md Retrieves the globally unique identifier (GUID) associated with an event handle. This GUID is used to identify the specific event stream. ```move public fun guid(handle_ref: &event::EventHandle): &guid::GUID { &handle_ref.guid.guid } ``` -------------------------------- ### Full Simple Blog Module in Move Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.en-US.mdx This snippet contains the complete `simple_blog` module, integrating all defined structures and functions. It covers blog definition, initialization, creation, name setting, article retrieval, addition, creation, update, and deletion. ```move module simple_blog::simple_blog { use std::signer; use std::string::{Self, String}; use std::vector; use moveos_std::account; use moveos_std::object::{Self, Object, ObjectID}; use simple_blog::simple_article::{Self, Article}; const ErrorDataTooLong: u64 = 1; const ErrorNotFound: u64 = 2; struct MyBlog has key, store { name: String, articles: vector, } /// This init function is called when the module is published /// The owner is the address of the account that publishes the module fun init(owner: &signer) { // auto create blog for module publisher create_blog(owner); } public fun create_blog(owner: &signer) { let articles = vector::empty(); let myblog = MyBlog { name: string::utf8(b"MyBlog"), articles, }; account::move_resource_to(owner, myblog); } public entry fun set_blog_name(owner: &signer, blog_name: String) { assert!(std::string::length(&blog_name) <= 200, ErrorDataTooLong); let owner_address = signer::address_of(owner); // if blog not exist, create it if (!account::exists_resource(owner_address)) { create_blog(owner); }; let myblog = account::borrow_mut_resource(owner_address); myblog.name = blog_name; } /// Get owner's blog's articles public fun get_blog_articles(owner_address: address): &vector { let myblog = account::borrow_resource(owner_address); &myblog.articles } fun add_article_to_myblog(owner: &signer, article_id: ObjectID) { let owner_address = signer::address_of(owner); // if blog not exist, create it if (!account::exists_resource(owner_address)) { create_blog(owner); }; let myblog = account::borrow_mut_resource(owner_address); vector::push_back(&mut myblog.articles, article_id); } public entry fun create_article( owner: signer, title: String, body: String, ) { let article_id = simple_article::create_article(&owner, title, body); add_article_to_myblog(&owner, article_id); } public entry fun update_article( article_obj: &mut Object
, new_title: String, new_body: String, ) { simple_article::update_article(article_obj, new_title, new_body); } fun delete_article_from_myblog(owner: &signer, article_id: ObjectID) { let owner_address = signer::address_of(owner); let myblog = account::borrow_mut_resource(owner_address); let (contains, index) = vector::index_of(&myblog.articles, &article_id); assert!(contains, ErrorNotFound); vector::remove(&mut myblog.articles, index); } public entry fun delete_article( owner: &signer, article_id: ObjectID, ) { // Implementation for delete_article would follow here, likely calling delete_article_from_myblog } } ``` -------------------------------- ### Get GUID Creation Number (Move) Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/move-stdlib/nursery/docs/guid.md Returns the creation number associated with a GUID. It accesses the 'creation_num' field within the 'id' field of the GUID structure. ```Move public fun creation_num(guid: &guid::GUID): u64 { guid.id.creation_num } ``` -------------------------------- ### Move Language Basics Explanation Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.zh-CN.mdx Explains the fundamental syntax and keywords used in Move smart contracts, including module declaration, use statements, constants, functions, and entry functions. ```APIDOC Move Language Basics: - `module module_name { ... }`: Declares a module, specifying its name and containing its logic. The syntax is `module address::module_name`. - `use dependency::path;`: Imports external libraries or types required for the contract's functionality. - `const CONSTANT_NAME: type = value;`: Defines constants, often used for error codes or fixed values within the module. - `fun function_name(parameters): return_type { ... }`: Defines a regular function. These functions are typically internal and cannot be called directly from outside the module without being wrapped by an entry function. - `public entry fun entry_function_name(parameters): return_type { ... }`: Defines an entry function, marked with the `entry` keyword. These functions can be invoked directly from external clients or scripts, acting as the public interface to the smart contract. ``` -------------------------------- ### Clone Move Repository Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/documentation/book/translations/move-book-zh/src/move-tutorial.md Clones the official Move repository from GitHub to your local machine. This is the first step to setting up the Move development environment. ```bash git clone https://github.com/move-language/move.git ``` -------------------------------- ### Initialize Rooch Project with npm Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/sdk/typescript-sdk/ts-sdk-quick-start.zh-CN.mdx Demonstrates the bash commands to create a new directory, navigate into it, and initialize a new Node.js project using `npm init -y`. This sets up the basic project structure for the SDK. ```bash mkdir sdk-quick-start cd sdk-quick-start npm init -y ``` -------------------------------- ### Get GUID ID Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/move-stdlib/nursery/docs/guid.md Retrieves the non-privileged ID associated with a GUID. The ID contains the creation number and the address of the creator. ```Move public fun id(guid: &guid::GUID): guid::ID) { *&guid.id } ``` -------------------------------- ### Start Rooch Local Server Source: https://github.com/rooch-network/rooch/blob/main/examples/rename_friend_module_trigger/readme.md Starts a local Rooch network server. This command initiates the server process, which is often a prerequisite for subsequent operations. ```shell rooch server start ``` -------------------------------- ### Start Rooch Local Server Source: https://github.com/rooch-network/rooch/blob/main/examples/rename_friend_module/readme.md Starts a local Rooch network server. This command is essential for running and testing Rooch applications in a development environment. ```shell rooch server start ``` -------------------------------- ### Get Creator Address Source: https://github.com/rooch-network/rooch/blob/main/third_party/move/language/move-stdlib/nursery/docs/guid.md Returns the account address that originally created the GUID. This is extracted from the GUID's internal ID structure. ```Move public fun creator_address(guid: &guid::GUID): address) { guid.id.addr } ``` -------------------------------- ### Start Rooch Server Source: https://github.com/rooch-network/rooch/blob/main/examples/blog/README.md Starts a local Rooch server instance. This is a prerequisite for deploying and interacting with Move contracts on the network. ```shell rooch server start ``` -------------------------------- ### TemplateContext Deep JSON Access Examples Source: https://github.com/rooch-network/rooch/blob/main/crates/testsuite/features/README.zh-CN.md Examples of accessing nested fields, array elements, and fields with special characters within JSON results. ```text # Nested fields: {{$.payment-channel[-1].execution_info.status.type}} # Array fields: {{$.payment-channel[-1].balances[0].amount}} # Dynamic key names (e.g., with special chars): {{$.rpc[-1]["object_type"]}} ``` -------------------------------- ### UniSat getBalance Example Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/sdk/wallet-integrate.en-US.mdx An example snippet demonstrating how a wallet like UniSat would implement the `getBalance` interface to return confirmed and unconfirmed balance information. ```ts getBalance(): Promise<{ confirmed: number; unconfirmed: number; total: string }> { return this.getTarget().getBalance() } ``` -------------------------------- ### Rooch CLI Commands Overview Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/blog-demo.zh-CN.mdx Displays the available commands and options when the 'rooch' executable is run without arguments. This output shows the primary tools for interacting with the Rooch network. ```APIDOC Usage: rooch Commands: account Tool for interacting with accounts init Tool for init with rooch move CLI frontend for the Move compiler and VM server Start Rooch network state Get states by accessPath object Get object by object id resource Get account resource by tag transaction Tool for interacting with transaction event Tool for interacting with event abi env Interface for managing multiple environments session-key Session key Commands rpc help Print this message or the help of the given subcommand(s) Options: -h, --help Print help -V, --version Print version ``` -------------------------------- ### Install Rooch TypeScript SDK Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/sdk/typescript-sdk/sdk-using-guide.en-US.mdx Installs the Rooch SDK package using npm. This is the first step to begin using the SDK in your TypeScript project. ```bash npm install @roochnetwork/rooch-sdk ``` -------------------------------- ### Create New Rooch Project Source: https://github.com/rooch-network/rooch/blob/main/docs/website/pages/build/tutorial/move-examples.en-US.mdx Demonstrates the use of the `rooch move new` command to initialize a new Move project. It highlights how project names with hyphens are handled and the importance of checking `Move.toml` for address aliases. ```shell rooch move new hello-world ```