Content platform

Endless CMS: A Step-by-Step Guide

Endless CMS: A Step-by-Step Guide

This document provides a complete, step-by-step guide to developing, deploying, and interacting with a simple Content Management System (CMS) DApp on the Endless blockchain. We will cover:

  1. Developing and Deploying the Move Smart Contract.

  2. Building a Rust CLI to Interact with the Deployed Contract.

By the end of this guide, you will have a fully functional decentralized application and a clear understanding of the end-to-end development process.


Part 1: The Move Smart Contract

In this section, we'll create, configure, and deploy the Move contract that powers our CMS.

Step 1.1: Initialize the Move Project

First, let's set up the project structure for our Move contract.

  1. Open your terminal in the endless-cms directory.

  2. Initialize a new Move package named endless-cms:

    # Make sure you are in the root project directory
    cd move
    endless move init --name endless-cms

    This command creates a standard Move project layout inside the move directory, including a sources folder for your contract code and a Move.toml manifest file.

Step 1.2: Create and Fund a Deployer Account

We need an account to deploy our contract. The endless CLI can create one for us.

  1. Run the initialization command:

  2. Follow the prompts:

    • Choose testnet for the network.

    • Press Enter when asked for a private key to generate a new one.

    The CLI will generate a new account, save its configuration in move/.endless/config.yaml, and automatically fund it with testnet EDS tokens.

  3. IMPORTANT: Copy the account address from the output. You will need it in the next step. It will look something like EGiHscDkCe9Giv7kwv8ha7bk61woSic4xpJ66UMc4XrA.

Step 1.3: Configure the Contract Manifest (Move.toml)

Now, we need to tell our contract where it will live and what other contracts it depends on.

  1. Open the move/Move.toml file.

  2. Add a named address for your contract under the [addresses] section. Use the account address you copied in the previous step. Let's call it cms_address.

  3. Add the EndlessFramework as a dependency under [dependencies]. This framework provides essential tools for building on Endless, like the Object model.

Step 1.4: Write the Smart Contract (cms.move)

Create a new file move/sources/cms.move and add the provided contract code.

(For brevity, the full code is omitted here. Copy the content from the file provided in the prompt.)

Key Functions Explained:

  • init_module(admin_signer: &signer): Called once upon deployment. It creates the PostCounter resource and stores it under the deployer's (admin's) account.

  • publish_post(admin_signer: &signer, author_signer: &signer, ...): This is a multi-agent function. It requires two signatures to execute:

    • admin_signer: To prove the caller has access to the PostCounter to assign a unique ID.

    • author_signer: To designate the post's owner. It creates a new Post as a separate Object on the chain.

  • edit_post(author_signer: &signer, ...): A single-signer function that allows the original author to modify a post's title and content. It verifies ownership by checking post_ref.author == signer::address_of(author_signer).

  • delete_post(author_signer: &signer, ...): Allows the author to permanently delete their post. It uses move_from to remove the Post resource and object::delete to destroy the Object itself.

  • get_post(post_address: address): A read-only #[view] function. It doesn't require a signature or a transaction. It fetches post data from the chain and returns it in a PostData struct.

Step 1.5: Compile and Deploy

Now, let's get the contract on-chain.

  1. Compile the code:

    This command checks for errors and builds the bytecode.

  2. Publish to the testnet:

    Confirm the transaction when prompted. After a few moments, the contract will be live! The output will show the transaction hash and confirm success. Your cms_address is now a published module.


Part 2: The Rust Client

With the contract live, we need an application to talk to it. We'll build a Rust CLI.

Step 2.1: Initialize the Rust Project

  1. Navigate to the root of your project (endless-cms).

  2. Create a new Rust binary project.

    (Assuming the src directory is already set up as a cargo project)

Step 2.2: Add Dependencies (Cargo.toml)

Open Cargo.toml and ensure the following dependencies are listed. They provide the tools for blockchain communication, command-line parsing, and data handling.

The [patch.crates-io] section is crucial. It tells Cargo to use specific versions of dependencies from git repositories instead of the default versions from crates.io. This is often necessary when working with rapidly developing blockchain SDKs to ensure all components are compatible.

Step 2.3: The Rust Code

Your project has four key files in src/:

  • main.rs: The entry point. Uses clap to define and parse CLI commands (create-account, publish-post, etc.).

  • cms.rs: The core logic for interacting with the smart contract.

  • event.rs: Defines Rust structs that match the Move events, allowing for easy deserialization.

  • post.rs: Contains default post content for easier testing.

Step 2.4: How the Client Calls the Contract

This is the most critical part. The functions in src/cms.rs are responsible for all on-chain communication.

IMPORTANT: Before running the client, open src/cms.rs and update the MODULE_ADDRESS constant to your contract address from Step 1.2.

1. Calling a View Function (e.g., get_post)

Read-only calls are simple and don't cost gas.

2. Calling a Single-Signer Function (e.g., edit_post)

For transactions that require only one signature, the HelperClient simplifies the process.

3. Calling a Multi-Agent Function (e.g., publish_post)

This is the most complex interaction, requiring manual transaction construction.


Part 3: Putting It All Together

Now you can use the Rust CLI to interact with your live contract.

  1. Create User Accounts: You need an admin (the same one that deployed the contract) and an author. Create JSON files for them.

  2. Fund the Author Account:

  3. Publish a Post:

    The command will print the PostPublishedEvent, which includes the post_address. Copy this address!

  4. Get the Post:

  5. Edit the Post:

    Post's title and content is update!

  6. Delete the Post:

    On https://scan.endless.link/ E7oERdbBYeFMPzu2MFUVaCRfEwxX6ELFcuZo9H4TXvsm is deleted.

Congratulations! You have successfully built, deployed, and interacted with a full-stack decentralized application on the Endless blockchain.

Last updated