Your subscription could not be saved. Please try again.
Thanks for subscribing.
We are excited to announce the early release of a new tool for Clarity smart contract development. “Early” release might be a stretch, because many community members were actually involved in the creation process, providing constant feedback and ideas for improvement. Additionally, just a few days ago, the project reached an important recognition milestone and is now available on Homebrew and Winget for more efficient installation.
We invite you to try it out and let us know what you think! Read on for the backstory, the features, and ways to get started.
Since the release of Stacks 2.0 in January, and the Clarity smart contracting language, writing and testing contracts has been difficult. The best testing framework available was ClarityJS SDK — a TypeScript library that provided access to the Clarity runtime. However, the library was cumbersome to use. Even simple things required workarounds and a great deal of boilerplate code. Troubleshooting was difficult, and the chain-state was only hardly observable.
With that being said, there were some other promising projects in the Stacks ecosystem: The language-server-protocol used in the VSCode Extension for Clarity, the Clarity REPL, and the Jupyter kernel to run Clarity code. However, they were all separate projects and hardly accessible for a beginner Clarity developer. As a result, an idea was born: What if there was a single CLI that would enable a productive flow - similar to the experience Rails is providing?
A few cycles later, and we released the first proof of concept. Codename: Clarinet.
Clarinet is our new go-to tool for local Clarity smart contract development. It is designed to facilitate rapid smart contract development, testing, and deployment. It consists of a Clarity REPL and a testing harness. These elements used in tandem allow you to rapidly develop and test a Clarity smart contract, without the need to deploy the contract to a local mocknet or testnet.
What does this mean in practice? Let’s take a look at the key capabilities…
Clarinet can create a folder structure and automatically organize configuration files to control your testing environment. The settings define available networks, associated accounts, token balances, and contracts to load before tests would be executed. You can even define contract dependencies!
Once your project is set up, you are only one command away from a new contract. It will create a new file for the contract as well as a boilerplate test-suite. Test-driven development couldn’t come any easier.
Clarinet comes with a TypeScript package for easy interactions with the Clarity runtime. It exposes objects to read and update the the chain, individual accounts, and contracts. To simplify contract interactions, the package also includes Clarity type support. Last but not least, the package includes an assert module, so you can define expected results and make assertions.
Here is a small, working test example for illustration purposes:
While you’re developing your contract, you will likely want to check if your contract is syntactically correct. Every contract configured in the project can be checked with a single command.
You can run defined tests and see results in your terminal.
You can even configure GitHub actions to run your tests automatically once you check-in your updates in a Github repository. Here is an example from the Arkadiko project.
Clarinet comes with an interactive console that can be used to interact with a Clarity runtime. As you would expect, all configured accounts and contracts will be available for usage. Once loaded, you will see a snapshot of the available contracts and accounts. This is a great way to experiment with the Clarity language.
Once you reach a high-enough confidence level of your implementation, you can use Clarinet to deploy your contracts to a mocknet. This way, you can start integrating the contract inside your app without repetitive, manual steps.
A little sneak peek for a feature currently in the works. A new command will make it easy for developers to spin up a local developer network with their contracts deployed. With that, developers can integrate contracts within their apps much quicker. Stay tuned for more!
With Clarinet becoming the new go-to tool for local Clarity smart contract development, we updated the documentation. Give it a try today:
As mentioned earlier, this was a project with fantastic community support. We wouldn’t be here without their help, so let’s give a big thank you to the following supporters - in no particular order: