This workshop is centered around a Move contract, designed to facilitate a voting system on the Sui blockchain. Accompanying the contract is a script enabling the execution of on-chain methods.
The contract serves as a foundation to explore various key concepts of blockchain development within the Sui ecosystem, such as object ownership, Table data structures, error handling, and NFT (Non-Fungible Token) lifecycle, including creation and display mechanisms. The workshop is crafted to provide a educational experience, bridging the gap between theoretical knowledge and practical application in blockchain technology.
Through this workshop, participants will gain hands-on experience with the Sui blockchain's unique features, empowering them with the skills to build decentralized applications (dApps).
Ensure you have the following installed:
-
Sui CLI: The command-line interface for interacting with the Sui blockchain. Installation instructions can be found in the Sui documentation.
-
Node.js: The runtime environment for executing JavaScript code server-side. You can download and install it from the official Node.js website. (IF YOU PLAN ON USING THE SCRIPT)
-
Git: Version control system to clone the repository. Install from git-scm.com if it's not already available on your system.
-
Clone the Repository: Obtain a copy of the source code on your local machine.
git clone https://github.com/4-point-0/sui_workshop.git
-
Publish the Smart Contract: Publish the package.
sui client publish --gas-budget <BUDGET_VALUE> --skip-dependency-verification
-
Use Node script OR CLI to invoke methods: Use the Node script or CLI to invoke the on-chain methods
CLI usage:
sui client call --package <PACKAGE> --module <MODULE> --function <FUNCTION_NAME> --args <ARGUMENTS> --gas-budget <BUDGET>
Node script usage:
GO AND CHANGE THE VALUES (addresses, packages etc.) IN METHODS BEFORE USING
- Go to script folder and install dependencies
cd scripts
npm i
- Call a method via the script
GO AND CHANGE THE ADDRESSES AND MNEMONICS IN THE SCRIPT SO YOUR WALLET IS SIGNING THE MESSAGE AND YOU'RE CALING YOUR CONTRACT METHOD
node script.js <METHOD_NAME>
The Sui Voting System contract provides a set of callable methods to interact with the polling system on the Sui blockchain. Below are the primary methods and their descriptions:
- Description: This method allows a user to create a new poll with a specified question and a list of options.
- Parameters:
question
: AString
representing the poll's question.options
: Avector<String>
representing the different choices available in the poll.
-
Description: Cast a vote in an active poll and receive an "I voted" NFT as a reward.
-
Parameters:
poll
: A reference to the activePoll
object.option
: Au64
index of the selected option from the poll.name
: AString
representing the voter's identity. (would be an wallet address, but for workshop simplicity we left this as a name string)
-
Description: Change the active status of a poll to either open or close it to further voting.
-
Parameters:
poll
: A mutable reference to thePoll
object.status
: Abool
flag representing the desired status (true
for open,false
for closed).
-
Description: Retrieve the current tally of votes for each option in a poll. (only for devInspect or dryRun through script)
-
Parameters:
poll
: A mutable reference to thePoll
object.