Mainnet Milestone: Third-Party Smart Contracts

Third-party smart contracts

As mainnet draws ever closer, we have another exciting update for our community, developers, and investors: support for third-party smart contracts is included at mainnet genesis!

This is a huge achievement as it means from the launch mainnet, anyone can deploy smart contracts on Dusk.

Third-party smart contracts were initially planned as a future update after mainnet launched, but it will be possible for developers and third-party organizations to deploy smart contracts from the beginning. 

What can be deployed?

Anything! Anyone can create a deployment transaction which includes a contract to be deployed, and take advantage of Dusk’s privacy and compliance. Deploying a contract is the first step toward creating decentralized applications, and for the first time developers will be able to use the full power of Rusk, the zero-knowledge friendly VM, or integrate with Citadel, Dusk’s privacy-preserving digital identity protocol. In the near future,  smart contracts will also have access to the full tokenization engine for compliant operations over real-world assets, through the Zedger protocol. We are excited to see  what developers will build and how they will take advantage of the privacy and compliance features Dusk put at their disposal.

What language are smart contracts deployed in? 

In principle, whatever can be compiled to Web Assembly can also be deployed on Dusk. This  gives developers more choice and freedom to code in the language that they like. 

The fact that developers can use such a broad selection of mainstream languages - we estimate that ~80% of developers use a language that can compile to Web Assembly and the majority of the biggest companies in the world use at least one of these languages - makes Dusk incredibly accessible for developers, enterprises, and institutions, reducing the learning curve for building and allowing developers to code using what they know and that their programs already use.

At Dusk, we primarily use Rust as our main programming language, which means our current development tools are centered around the Rust ecosystem. However, it is already possible to work with other languages such as JavaScript, C/C++, Kotlin, Python, C#, and more. Looking ahead, we are committed to expanding our devtools to support a wider range of technologies, enabling the development of contracts across multiple languages for broader adoption.

No APIs needed for storage

One advantage for developers is that there's no need for a separate storage API—any Rust program is automatically stored correctly on Dusk. This makes it much easier for developers who are new to blockchain, such as those from traditional institutions, by significantly lowering the learning curve. Unlike most blockchains, which separate data and code, Dusk keeps everything together by storing the entire memory snapshot.

Dusk preserves the entire memory state of a contract between executions. This means you don't need a special storage API; the memory is treated as persistent state. Developers can use familiar data structures, like Rust's BTreeMap, and be assured that their data (collections, structures, variables) will be saved and remain consistent across different method calls. Even a simple variable like 'count' will be preserved. However, only 'static' or 'global' data is saved; temporary data within methods will not be. This approach is very intuitive and straightforward for any programmer to use.

Here's the simplified breakdown on how data is stored and maintained in a smart contract on the Dusk blockchain:

1. Persistent Memory: When a smart contract runs, its memory (the data it works with) is saved between different executions. This means that you don't need a special system just to manage storage, as the entire memory is treated like state (or persistent data).

2. Using Familiar Data Structures: The person writing the contract can use common data structures from the programming language they're working with (for example, in Rust, they could use something like a BTreeMap). These data structures are automatically preserved between different times the contract is run, so the developer doesn’t have to worry about managing their storage manually.

3. Variables are Saved: If a developer uses a simple variable, like one called `count` that holds a number, this value will also be saved and kept safe between different runs of the contract.

4. Static or Global Data: Only variables or data structures that are marked as 'static' or 'global' will be preserved. Temporary data created in a single method won't be saved for future runs.

The goal is to make this system intuitive and familiar for programmers, so they can work with contracts without needing to learn complicated storage techniques.

Final thoughts

From Day One, Dusk will support third-party smart contracts, making them efficient and easy to develop. Our architecture is designed with institutions and enterprises in mind, ensuring a simple and familiar experience that makes blockchain technology accessible and user-friendly.

Many blockchain platforms use languages that are unfamiliar to programmers and don't integrate well with existing codebases. In contrast, Dusk is built to simplify the deployment of smart contracts by allowing the use of popular programming languages.

We are proud of our efforts to enable and optimize third-party smart contracts, establishing a strong foundation for a dynamic and robust ecosystem.