Technical Documentation
This technical documentation offers an in-depth analysis of the Red Packet Project's system architecture and smart contract functionalities, detailing the technical implementation and operation.
Introduction
The Red Packet Project brings the tradition of red packet (hongbao) gifting into the digital age, utilizing blockchain technology to create a seamless and secure NFT-based system. At the core of this implementation is the ERC-6551 standard, which allows red packets to function as token-bound accounts (TBAs), enabling more flexible and feature-rich interactions. This document outlines the technical architecture and functionality of the red packet system using ERC-6551.
1. What is ERC-6551?
ERC-6551 is a standard that defines token-bound accounts (TBAs), allowing NFTs to operate as accounts that can hold assets, execute transactions, and interact with smart contracts. This is a crucial feature for the Red Packet Project, as it allows each red packet NFT to manage its own wallet, hold ETH or ERC-20 tokens, and interact with multiple recipients in a dynamic way.
2. Red Packet System Architecture
The Red Packet Project leverages the ERC-6551 standard to enable red packets to act as self-contained accounts with the ability to store and distribute digital assets. Below is a breakdown of the technical architecture:
a. Red Packet Contract (ERC-6551 Account Contract)
Each red packet created on the platform is an ERC-6551 token-bound account (TBA). The key features include:
Ownership of Assets: The red packet account can hold ETH and ERC-20 tokens, which will be transferred to the recipient(s) upon claiming.
Execution of Transactions: The red packet account can send and receive assets, allowing for flexible gifting scenarios, such as sending to multiple recipients.
Account Management: Each red packet NFT has its own account address that is tied to the userβs wallet, enabling seamless interaction between the NFT and external contracts.
b. Smart Contract Functions
Key functions within the smart contract are:
createRedPacket(uint256 amount, address recipient, string memory cover): This function allows the user to create a new red packet, specifying the amount (in ETH or ERC-20 tokens), recipient address, and the cover design. The red packet NFT will be initialized as an ERC-6551 token-bound account.
claimRedPacket(uint256 packetId): Allows the recipient to claim the contents of the red packet. The function transfers the amount from the red packet's account to the recipient's wallet.
multiRecipientSupport(uint256 amount, address[] memory recipients): In Phase 3, this function will enable a red packet to be sent to multiple recipients at once by distributing the specified amount among the recipients.
addCustomMessage(string memory message): In Phase 3, this function allows users to include a personalized message with the red packet, stored as metadata on-chain.
Last updated