Creating a custom PSP
This tutorial helps you build a custom Private Solana Program from scratch.
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:
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 psp: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. 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.
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!