Creating a custom PSP
This tutorial helps you build a custom Private Solana Program from scratch.
If you're new to Light Protocol, we recommend following the quick start tutorial on how to build private payments first.
At a high level, here's what you'll accomplish in this tutorial:
- 1.Initialize and build a fresh PSP project
- 2.Customize the PSP to fit your use case
Building PSPs becomes easier if you
First, make sure you install the following:
- Go here to install Solana and then run
solana-keygen newto create a keypair at the default location. Light uses this keypair to run your program tests. We also recommend checking out the official Solana developers page.
Install the Light CLI globally:
npm install -g @lightprotocol/cli
yarn global add @lightprotocol/cli
Then go ahead and initialize a new PSP anywhere in your terminal:
light init firstPSP
This will create a fully-fledged boilerplate project with all you need, including an on-chain program, client, and circuit template for a time-locked token escrow. When you open the project in your IDE, you might get a message asking you whether you want to restart the project as a docker devcontainer - Please click yes if you're a MAC m1/m2 user. The project scaffold should look like this:
Fairly standard. If you've used anchor before, this will seem very familiar. The anchor program in
/programsis a generic app verifier template. Since in a PSP the program logic is moved from the on-chain program to the client (the constraints are enforced by the circom circuit at proof generation time), we don't need to worry about the code in /programs for now.
Notice how there's a
firstPSP.lightfile inside the
circuitfolder. This is macro-circom, which takes the data you specify in the
.lightfile and expands it into a fully fledged circom circuit, including all the boilerplate.
Let's take a look at the
firstPSP.lightfile: We can see two macro keywords: [instance]. [LightTransaction].
instance defines the "config"; you can set
nrAppUtoxstoto whatever amount of input UTXOs your PSP should allow.
publicInputsare whatever constraints you want to be public (e.g. timeslot to check against).
LightTransaction lets you define what data should be stored in the UTXO. The rest is what we do.
Feel free to adapt the PSP to your liking.
The nuances of building the client are based on your specific use case. We recommend you use the default template client as a starting point! It shows you how to call the relevant user methods, such as
Once you're done implementing the client, you're ready to build and deploy your PSP!
We're continuously working to make your experience building Private Solana Programs as easy as possible. We'd love to hear your feedback. Join other Light users and the core devs in our Discord and reach out!