Pact 5 Beta: Improving Developer, Miner, and User Experience

Pact 5 Beta: Improving Developer, Miner, and User Experience
Jose Cardona

Jose Cardona

September 23, 2024

Previously, we announced that a new age in the life of the Pact smart contract language was coming. Well, get ready because we’ve got some great news for you in this article! Timelines shifted sometime mid-year by about three months due to various partnerships taking priority, but we’re pleased to announce that Pact 5 is coming. Pact 5 Beta is the final step before the Mainnet release!

We’re releasing a follow-up version of Chainweb 4.25 with a point release 4.25.2 on its test network to allow users, developers, node operators, and miners to test the new interpreter in a live environment. The full mainnet release for Pact 5 will come later this year, with Chainweb 4.26. In this release, Pact 5 is on full showcase for users to interact with in a professional production environment, along with an improved local experience regarding the broader Pact ecosystem.

So, what does Pact 5 bring? Let’s get into it.

A Better Developer Experience

Pact 5 answers the diverse and consistent feedback from the community and the various telemetry and data we’ve been collecting for years. In particular, we’ve made efforts to address many warts and loads of bug fixes in the development process at the code level.

Improved Errors

Errors in past versions of Pact have often needed to be clarified for new developers. Pact 5 optimizes for error readability in a way that supports a smoother learning curve for budding Pact developers.

For example, in the past, if a developer were to deploy a module and run a script with an error, they would receive an error like this:

Alternative text

In the new and improved Pact 5 error reporting scheme, we have the following:

Alternative text

It's much more readable! In the same vein, there are many in-kind improvements to various other types of errors, and developers need only upgrade to see them improve at no additional cost to them.

Improved Gas Logs

Pact 5 enables a new form of gas log, allowing developers to see exactly how much gas is consumed by their code, line by line. This granularity enables developers to fine-tune and optimize their Pact code for efficiency.

Debug Flags

In Pact 5, we’re introducing new debug flags in the repl for inspecting the compiler's transformations. Additionally, Pact 5’s revamped error feedback provides clearer, more intuitive error messages, significantly improving debugging. When optimizing or diagnosing bugs in contracts, it helps to break down code into its various intermediate forms to identify issues without just throwing code to unit and gas tests and hoping that’s enough.

Simply issue the following, and you can print out the stages of the compilation process to inspect your code:

Alternative text

Performance Improvements

In Pact 5, we've performed various optimizations to the way that contracts and values are represented in our backend. Builders can expect redeployed modules to take up less space, which has also vastly improved dynamic loading and linking times. Projects like decentralized exchanges (DEXs), NFTs (Marmalade), and even traditional token transfers will see improvements.

New Language Features

As an observation of the way users wrote Pact code, we have made a few improvements to the language:

  • There is no longer a difference between let and let* forms. They mean the same thing and cost the same gas.
  • You no longer need to introduce an unused variable to be able to introduce statements, such as (let* ((_ 0)) (thing1) (thing2) (thing3)). The new do form allows the same, allowing you to write (do (thing1) (thing2) (thing3)).
  • A longstanding issue with our cond form has been fixed. Previously, cond had an issue with the final expression being an application.
Alternative text

Now, cond will work as intended:

Alternative text
  • We have introduced (suspend x) as a shorthand for (lambda () x) , for lazy values
  • Capability applications now produce capability "tokens," which can be let-bound and put in lists. These tokens do not evaluate the capability body unless used within with-capability.

The following now works in Pact 5:

Alternative text
  • We have a variety of new reply natives useful for debugging contracts, such as env-module-admin (which allows you to acquire module admin for any module in the reply only). Pact 5, as a rewrite, allows us to provide tooling and facilities to users much more easily.

Along with these improvements, we also support a new and improved LSP that includes many features that one would expect from a fully-fledged LSP environment for a programming language and an up-to-date Kadena.js toolkit supporting Pact 5.

Pact 5 Goes Live!

Pact 5 Beta is set to be available to the public on its own private test network on September 25, 2024. Staging this beta on its own network gives us the ability to retain a stable test network for older Pact versions live on mainnet right now, as well as the ability to thoroughly test the new interpreter in a live setting with users just to make sure it’s as seamless a transition as possible when mainnet Pact 5 is finally here. If all goes well, the mainnet release date for Pact 5 will come with the Chainweb 2.26 release later this year.

Conclusion

Pact 5 introduces new language features aimed at streamlining the development experience, including support for enhanced debugging tools and the ability to test code fragments. These updates reduce development time and increase flexibility, making it easier for developers to build and iterate quickly.

In addition, mining efficiency has been drastically improved in Pact 5, allowing miners to spend less time executing Pact code and more time securing the network. With faster transaction times and reduced DOS vectors, overall network security and performance have been significantly bolstered.

So the question remains: why are we making such a big fuss about Pact 5? The answer is complex. For one, Kadena cares about the public mainnet and wants to ensure Pact can make it for the long haul in the ecosystem. We’re future-proofing the blockchain because we’re bullish on Kadena. Second, we want Pact 5 because it sets us on a very principled footing for future projects integrating with 3rd parties and building capabilities into the compiler for long-term projects.

Faster Transaction Execution & Improved Diagnostics

Ultimately, Pact 5 isn’t just about performance enhancements or new features. It’s about enabling faster transaction execution and improving the overall efficiency of dApps built on Kadena. The improved diagnostics and testing capabilities make it easier for developers to refine their code, leading to faster deployment and a more seamless experience for users.

Test Your Code and Be Part of Pact’s Future!

The purpose of this Beta is to expand on testing coverage and deepen benchmarking. We seek users currently deployed or interested in deploying to a production environment to test their code on the testnet05 staging environment. The goal is to verify that everything works smoothly without regressions. Additionally, we want to monitor a live production environment to assess if latency changes before moving forward with the mainnet deployment. Join us on Discord for more information on testing.

Pact 5 is an investment in you!