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:
Developing and Deploying the Move Smart Contract.
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.
Open your terminal in the
endless-cmsdirectory.Initialize a new Move package named
endless-cms:# Make sure you are in the root project directory cd move endless move init --name endless-cmsThis command creates a standard Move project layout inside the
movedirectory, including asourcesfolder for your contract code and aMove.tomlmanifest 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.
Run the initialization command:
Follow the prompts:
Choose
testnetfor the network.Press
Enterwhen 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 testnetEDStokens.IMPORTANT: Copy the
accountaddress from the output. You will need it in the next step. It will look something likeEGiHscDkCe9Giv7kwv8ha7bk61woSic4xpJ66UMc4XrA.
Step 1.3: Configure the Contract Manifest (Move.toml)
Move.toml)Now, we need to tell our contract where it will live and what other contracts it depends on.
Open the
move/Move.tomlfile.Add a named address for your contract under the
[addresses]section. Use the account address you copied in the previous step. Let's call itcms_address.Add the
EndlessFrameworkas a dependency under[dependencies]. This framework provides essential tools for building on Endless, like theObjectmodel.
Step 1.4: Write the Smart Contract (cms.move)
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 thePostCounterresource 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 thePostCounterto assign a unique ID.author_signer: To designate the post's owner. It creates a newPostas a separateObjecton 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 checkingpost_ref.author == signer::address_of(author_signer).delete_post(author_signer: &signer, ...): Allows the author to permanently delete their post. It usesmove_fromto remove thePostresource andobject::deleteto destroy theObjectitself.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 aPostDatastruct.
Step 1.5: Compile and Deploy
Now, let's get the contract on-chain.
Compile the code:
This command checks for errors and builds the bytecode.
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_addressis 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
Navigate to the root of your project (
endless-cms).Create a new Rust binary project.
(Assuming the
srcdirectory is already set up as a cargo project)
Step 2.2: Add Dependencies (Cargo.toml)
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. Usesclapto 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.
Create User Accounts: You need an admin (the same one that deployed the contract) and an author. Create JSON files for them.
Fund the Author Account:
Publish a Post:
The command will print the
PostPublishedEvent, which includes thepost_address. Copy this address!Get the Post:
Edit the Post:
Post's title and content is update!
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