Automatically generate Candid from Rust on the IC

David Dal Busco
2 min readMar 12, 2023
Photo de Karsten Würth sur Unsplash

Update July 22nd, 2023: There is now a better way to automatically generate Candid from Rust. Check out my new blog post about that subject!

The ability to auto-generate the Candid declaration from Rust code on the Internet Computer is expected to become available in the second quarter of 2023.

In the meantime, a workaround can be used to generate these types, which I notably use in my open-source Blockchain-as-a-Service project, Juno.

Here’s how you can implement the workaround yourself.

Want to start building decentralized apps without learning a new programming language? Check out Juno, the open-source Blockchain-as-a-Service platform that makes it faster and easier than ever before to build dapps with frontend code only! ⚡️🚀🤯

1. Annotate

Because this solution involves a workaround, the first step is to annotate the public methods that need to be exported to Candid types.

To do this, use the candid_method macro of the Candid crate, specifying the export type and, if necessary, the query type. The default is update.

use ic_cdk_macros::{query, update};
use ic_cdk::export::candid::{candid_method};

#[candid_method(query)]
#[query]
fn hello(name: String) -> String {…

--

--