Validator Tutorial - Randgen Hub Voter as the example
Last updated
Was this helpful?
Last updated
Was this helpful?
A TypeScript-based Command Line Interface (CLI) and SDK to interact with the Randgen Hub on the Mind Network. This tool provides functionalities such as voter registration, reward checking, encryption, and anonymous voting powered by Fully Homomorphic Encryption (FHE). The hub is live and accessible at .
Voter Registration: Register your hot wallet as a voter in the Randgen Hub.
Reward Checking: Check voting rewards associated with your hot and cold wallets.
Anonymous Voting: Perform one-time or continuous voting in eligible rounds, with anonymity guaranteed by FHE.
Fully Homomorphic Encryption (FHE): Leverage FHE for secure and privacy-preserving voting.
Encryption: Encrypt data using the FHE key set.
Vote Submission: Submit encrypted votes to the Randgen Hub.
SDK for Programmatic Usage: Use the SDK to integrate functionalities into your own projects.
Node.js (version 20 or later)
npm (Node Package Manager)
Clone the repository
Navigate to the project directory
Install dependencies:
Build the project:
Run the CLI:
The CLI provides various commands for interacting with the Randgen Hub. Below is a list of available commands:
Registers the hot wallet as a voter in the Randgen Hub.
Arguments:
hotWalletPrivateKey
(optional): Private key of the hot wallet used for voting.
coldWalletAddress
(optional): Cold wallet address to receive voting rewards.
Checks the voting rewards for the hot and cold wallets.
Options:
--hot-wallet-private-key
: Private key of the hot wallet.
--cold-wallet-address
: Address of the cold wallet.
Fetches and displays the Fully Homomorphic Encryption (FHE) key set.
Encrypts a given number using FHE.
Arguments:
number
: The number to encrypt.
Submits a vote using an encrypted ciphertext URL.
Arguments:
ciphertextUrl
: The URL of the encrypted vote.
hotWalletPrivateKey
(optional): Private key of the hot wallet used for voting.
Performs a single voting action in the Randgen Hub.
Arguments:
hotWalletPrivateKey
(optional): Private key of the hot wallet used for voting.
Continuously votes in every eligible round in the Randgen Hub.
Arguments:
hotWalletPrivateKey
(optional): Private key of the hot wallet used for voting.
You can integrate the project programmatically into your TypeScript or JavaScript projects by using the SDK.
Install the SDK using npm:
The following functions are available for import:
registerVoter
: Register a voter in the Randgen Hub.
checkHotWalletReward
: Check rewards associated with the hot wallet.
checkColdWalletReward
: Check rewards associated with the cold wallet.
fetchFheKeySet
: Fetch the FHE key set for encryption operations.
encrypt
: Encrypt a number using the FHE key set.
submitVote
: Submit a vote using an encrypted ciphertext.
voteOnce
: Perform a one-time vote in the Randgen Hub.
voteContinuously
: Continuously vote in all eligible rounds in the Randgen Hub.
Here is an example of generating a random number, encrypting it, and submitting a vote.
The CLI and SDK use a configuration file to store required settings. You can find the configuration in src/config.ts
.
Configuration values like hotWalletPrivateKey
can also be provided as environment variables:
Refer to src/config.ts
for more configuration options.
Command parameters > environment variables > config.ts
The following scripts are available:
npm run build
: Compiles the TypeScript code into JavaScript.
npm run cli
: Builds and runs the CLI tool.
npm run abi
: Generates TypeScript bindings for smart contract ABIs using typechain
.
This project is licensed under the MIT License.