For the complete documentation index, see llms.txt
Private party tutorial
Prerequisites: complete Hello World first. This tutorial assumes you can compile a contract and run a local devnet.
This is the first real contract on the learning path. It is about the privacy boundary: the exact point where a user's private data becomes public. Compact keeps data private by default, so you decide where that point is and you put it there on purpose.
A party organizer deploys the contract. Guests RSVP without revealing who they are, then pay an entry fee in NIGHT when they arrive. NIGHT is an unshielded token, and unshielded transfers are always public, so paying the fee is where each guest crosses the boundary. Along the way you will see:
- The privacy boundary. Guests stay private until they pay the unshielded NIGHT entry fee at check-in. The organizer stays private until they claim the fees.
- A salted commitment. The RSVP list holds a
persistentCommitof each guest's address, salted with the guest's secret, so the list reveals nothing about who is on it. - A DApp-specific public key. The organizer is identified by a
persistentHashof a secret, not by a wallet address, and that key gates the organizer-only circuits. - Unshielded NIGHT in and out.
receiveUnshieldedtakes each guest's fee andsendUnshieldedpays the total to the organizer. - A state machine. A
PartyStateenum decides which circuits can run at each stage of the party.
The source for this tutorial is
examples/private-party
in midnight-examples.
Set up
Clone midnight-examples, install the workspace, and compile every contract:
git clone https://github.com/midnightntwrk/midnight-examples.git
cd midnight-examples
yarn install && yarn compile
Then move into the example:
cd examples/private-party
You'll start the local network in the second part, when you run the tests.
Private party contract
Read a contract that keeps guests private behind salted commitments and gates the organizer's actions with a DApp-specific key, then makes guests public at exactly one point: the NIGHT entry fee.
Private party tests
Run the party on a local devnet with MidnightJS: RSVP, check in, claim the fees, and watch the contract turn away the wrong callers.