Introduction
This guide will walk you through the process of creating, testing, and submitting an assertion usingpcl. By the end of this tutorial, you’ll understand how to:
- Set up your project structure
- Test your assertion
- Deploy your contract
- Authenticate with
pcl - Create a project
- Store your assertion
- Submit your assertion to the Credible Layer
- Deploy your assertion
- Verify that the assertion is working
Prerequisites
Before you begin, make sure you have:pclinstalled (see the Installation Guide)- Solidity compiler installed
- Foundry installed (see the Foundry Installation Guide)
- A browser wallet for authentication (MetaMask or similar)
- Access to the Credible Layer Demo, reach out to us on Telegram if you’re interested in getting access
1. Project Setup
We’ve created an example project with containing some complete assertion examples that work out of the box and that you can use as a starting point for your own projects. The project can be found here. For a detailed understanding of what an assertion is and how it works, see the Assertion Guide. For testing assertions, see the Testing Assertions guide.The
credible-layer-starter repo has several examples that you can deploy and try out once you’re done with this guide.
Specific instructions can be found in the README.2. Running Tests
Use thepcl CLI to run your tests:
3. Deploy Your Contract
You can deploy the Ownable contract using the following command:<RPC_URL>: The RPC URL of the network you’re deploying to<PRIVATE_KEY>: The private key of the account you used to sign in to the dApp<DEPLOYER_ADDRESS>: The address of the account you used to sign in to the dApp
Deployed to: address in the output of the command.
4. Authenticating with Credible Layer
Here’s a full video that you can consult to follow along with the process entire process from authentication to activating the assertion:
Before submitting your assertion, you need to authenticate:
Make sure to use the same address as you set as the initial owner of the contract in the previous step.
- Your wallet has the correct network selected
- The
pclCLI uses the correct url - You have an internet connection
- The
pclCLI is properly installed
5. Create a Project
Once you have deployed your contract, you’ll need to create a project in the dApp if you don’t have one already. Navigate to the browser window opened by thepcl auth login command and create a new project. When asked to link your contract, use the address of the contract you deployed in the previous step.
For a more detailed overview of how to use the dApp and manage projects, see the dApp Guide.
6. Storing Your Assertion
Next, store your assertion in the Assertion Data Availability layer (Assertion DA):OwnableAssertion is the name of the assertion.
This command submits your assertion’s bytecode and source code to be stored by the Assertion DA, making it available for verification by the network.
7. Submitting Your Assertion
Finally, submit your assertion to the Credible Layer dApp:pcl store command:
<project_name> is the name of the project you created in the dApp, capitalized in the same way as you did when creating the project.
8. Deploying Your Assertion
Last step is to go to the dApp and deploy the assertion. Go back to the url that you opened with thepcl auth login command and navigate to the project that the assertion was added to.
You’ll notice that there’s one assertion ready for deployment. Go ahead and proceed to review and deploy it. During the review process, you’ll choose whether to deploy to Staging (for testing) or Production (for active protection).
After deployment, your assertion enters a timelock period. During this period, it is marked for enforcement (production) or marked for staging (staging environment). After the timelock expires, the assertion becomes enforced (production) or staged (staging), actively protecting your contract. See the Glossary for details about timelocks.
9. Verify That The Assertion Is Working
Now that your assertion is deployed and enforced (after the timelock period), let’s verify that it’s working as expected. We’ll do this by attempting to change the ownership of the contract, which should trigger our assertion and prevent the change. First, let’s check the current owner of the Ownable contract. ReplaceADDRESS_OF_OWNABLE_CONTRACT with the address of your deployed Ownable contract and RPC_URL with your network’s RPC URL:
NEW_OWNER_ADDRESS with an address that is not the initial owner and PRIVATE_KEY_OF_THE_OWNER with the private key of the owner of the contract. This transaction should cause the assertion to revert, which will result in the transaction being dropped:
Conclusion
Congratulations! You’ve successfully created, tested, deployed, and verified your first assertion usingpcl. You can now go ahead and start implementing assertions in your own projects.
Next Steps
- Read the Assertions Book: Check out the Assertions Book for more detailed explanations and a collection of assertions for various use cases
- Try more complex assertions: We’ve created some more assertions in the credible-layer-starter repo that are ready to be deployed and used with a couple of commands
- Integrate with your own projects: Apply assertions to your existing smart contracts
- Join the community: Share your assertions and learn from others in the Phylax Telegram
pcl and its commands, see Using pcl and pcl Reference.
For a comprehensive list of terms and concepts used in the Credible Layer, see the Glossary.
