Skip to main content
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 persistentCommit of 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 persistentHash of a secret, not by a wallet address, and that key gates the organizer-only circuits.
  • Unshielded NIGHT in and out. receiveUnshielded takes each guest's fee and sendUnshielded pays the total to the organizer.
  • A state machine. A PartyState enum 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.