[Supa] [Tutorial] Designing Public vs. Private State: What Goes Where and Why#563
Open
JirA44 wants to merge 1 commit into
Open
[Supa] [Tutorial] Designing Public vs. Private State: What Goes Where and Why#563JirA44 wants to merge 1 commit into
JirA44 wants to merge 1 commit into
Conversation
|
Supa seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Designing Public vs. Private State: What Goes Where and Why
Introduction
When building decentralized applications (dApps), it's essential to decide what data belongs in the public ledger versus what remains private. This tutorial will guide you through the process of designing your dApp's state management, covering exported vs non-exported ledger fields, the implications of
disclose(), shielded vs unshielded token choices, and common mistakes.Exported vs Non-Exported Ledger Fields
When defining your data structure for the public ledger, consider what fields can be safely exposed to users. Non-exported ledger fields are those that should remain private and not be written to the blockchain in their entirety.
Example:
Suppose we're building a simple token-based economy where each user has a balance on the blockchain. We want to expose the
balancefield but keep the private user ID (id) hidden.Implications of
disclose()The
disclose()function allows you to explicitly specify which non-exported fields should be written to the public ledger. This is particularly useful when working with shielded tokens, where the underlying private data remains confidential.disclose()to expose specific parts of your private state to the public ledger.Example:
Shielded vs Unshielded Token Choices
When deciding between shielded and unshielded tokens, consider the following factors:
Example:
Common Mistakes
When managing your dApp's state, be aware of the following common mistakes:
Example:
Decision Trees for Common dApp Patterns
Here are some common dApp patterns and decision trees to help you design your state management:
Conclusion
Designing your dApp's state management is crucial for security and scalability. By understanding the differences between exported and non-exported ledger fields, the implications of
disclose(), and common mistakes, you can create a secure and efficient state management system.Closes #292
🤖 supa resolutionengine.js