In the landscape of marketing, the integration of interesting technical and design solutions can open up exciting opportunities. The gift code mechanism in ZkNoid’s Lottery is a prime example of this, presenting both challenges and triumphs in its implementation.
With our latest proposal, we have successfully developed a reliable system that allows players to gift lottery tickets to friends or make giveaways on social media platforms like Twitter by sharing unique codes. Today we’re going to explore the intricacies of promo codes on ZkNoid, learn how you can use them, and provide insights of their generation and functionality.
The process of purchasing a gift code
Upon entering the ZkNoid Lottery zkApp, users are greeted with two buttons: one for using an existing gift code and another for generating a new one. These buttons are the backbone of the gift code mechanism.
In order to buy a promo code, users simply needs to click the “Generate gift access code” button.
This action leads them to a screen displaying any previously purchased codes. If users wish to buy new codes, they need to specify the desired quantity.
Once the number of gift codes is selected, users can proceed by clicking the “pay” button. This trigers a wallet transaction where users are required to provide a signature and confirm the payment transaction.
After the payment is processed, a new promo code is generated and added to the list of available codes. However, it’s important to note that the purchased gift code requires payment finalization before it can be be activated. This precaution is in place to mitigate potential risks from malicious actors who might attempt to fork the network and remove payment transactions after acquiring a promo code.
To ensure security, users are required to wait for 60 blocks to pass after their payment has been included in the blockchain. Only then will the gift code transition to a “Ready to use” state, making it available for sharing with friends or followers.
Process of using a gift code
If a user has received a gift code and is ready to redeem it, he needs to click the “Use gift access code” button in the ZkNoid interface.
This will prompt the user to enter your gift code which is automatically validated. The status of the code will be displayed, informing whether it is valid and available for use.
Upon entering a valid code, the user will receive a lottery ticket. Next, it’s time to select the ticket numbers. There are two options:
- Manual entry: Fill in chosen numbers by hand.
- Random selection: Clock the “Random numbers” button to automatically generate numbers for you
After selecting the number, click the “Confirm ticket number”. The system will request your signature to authorize the transaction. Once confirmed, the transaction will be executed on the backend, and you will see your ticket appear in your account after the next block is produced on the blockchain.
Architecture of gift code generation mechanism
When a user generates new promo codes, they’re created locally within their browser. The generated codes are then hashed as CircuitString and the signature of the hashed promocodes is requested. Finally, the user is prompted to confirm the payment in his wallet.
Once payment is complete, all relevant data: the generated codes, signature, and payment hash are sent to the backend and stored in MongoDB to be processed by a backend worker.
The backend worker, named approve-gift-codes, performs several checks:
- Signature verification. The system ensures that the signature data corresponds to the hashed promo codes and verifies that the signer is indeed the sender of the payment transaction. This identifies the user who generated the gift code and verifies his intention to buy the following gift code. It’s impossible for an attacker to make a request for codes bought by other users since the attacker can’t fake the user’s signature.
- Payment transaction validation. The backend checks that the transaction was successful, finalized, sent to the correct ZkNoid treasury address, and that the transaction hash hasn’t been processed before. Additionally, it verifies that the transaction amount matches to $MINA cost of the requested number of gift codes.
If all the checks are passed, the gift codes are extracted from the request and stored in the gift codes database.
Architecture of gift codes usage mechanism
When a user enters a gift code, it’s checked against the gift codes database. If it exists, it’s status is returned and shown to the user. If the gift code is valid and has not been previously used, the user is prompted to choose ticket numbers. After choosing, a request to purchase a ticket is created and stored to MongoDB. The gift-ticket-buyer service then processes the request. It marks the promo code as used and executes the buy ticket transaction, competing the process for the user.
Conclusion
The integration of gift codes in ZkNoid’s Lottery not only enhances user engagement but also strengthens community ties through gifting and sharing opportunities. By understanding the mechanics behind generating and using these codes, players can be assured of its security and fully leverage this feature.
Whether you’re looking to share a ticket with a friend or host a giveaway for your community, the ZkNoid gift code system provides an exiting and robust way to engage with the Lottery.