A quickstart guide to writing assertions and using the Credible Layer CLI
This guide will walk you through the process of creating, testing, and submitting an assertion using the pcl
(Phylax Credible Layer) CLI. By the end of this tutorial, you’ll understand how to:
pcl
Before you begin, make sure you have:
pcl
CLI installed (see the Installation Guide)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.
You can clone the example project by running the following command:
Once cloned you have a repository with all required dependencies.
Use the pcl
CLI to run your tests:
This command will compile your assertion and run the tests. You should see output looking like this indicating that the tests have passed:
If your tests fail, check for these common issues:
You can deploy the Ownable contract using the following command:
Explanation of the arguments:
<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 dAppMake sure to note down the address of the deployed contract as you’ll need it to create a project in the next step.
It will be the Deployed to:
address in the output of the command.
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.
This will provide you with with a URL and an authentication code that you can use to authenticate with the Credible Layer.
If authentication fails, ensure:
pcl
CLI uses the correct urlpcl
CLI is properly installedOnce 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 the pcl 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.
Next, store your assertion in the Assertion Data Availability layer (Assertion DA):
Here 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.
Finally, submit your assertion to the Credible Layer dApp:
This will prompt you to select the project and assertion(s) you want to submit. Follow the interactive prompts to complete the submission.
Alternatively, you can specify the project and assertion directly as per the output of the pcl store
command:
Note, that <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.
Last step is to go to the dApp and activate the assertion. Go back to the url that you opened with the pcl auth login
command and navigate to the project that the assertions was added to.
You’ll notice that there’s one assertion ready for submission, go ahead and proceed to review and activate it.
For a more detailed overview of how to use the dApp, see the dApp Guide.
Now that your assertion is activated, 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. Replace ADDRESS_OF_OWNABLE_CONTRACT
with the address of your deployed Ownable contract and RPC_URL
with your network’s RPC URL:
This command should return the initial owner address that was set when we deployed the contract.
Next, let’s attempt to transfer ownership to a new address. Make sure you replace 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 trigger the assertion and revert:
The transaction should timeout after about 20 seconds which means that the assertion reverted the transaction:
To confirm that the ownership hasn’t changed, let’s check the owner again:
The owner should still be the original address, confirming that our assertion successfully prevented the ownership change.
Congratulations! You’ve successfully created, tested, activated and verified your first assertion using the Credible Layer CLI. You can now go ahead and start implementing assertions in your own projects.
For more detailed information about the Credible Layer CLI and its commands, see the CLI Reference Guide.
For a comprehensive list of terms and concepts used in the Credible Layer, see the Glossary.