Scale Functions currently support using Rust as a Guest language.

This means that you can write your Functions in Rust (Guest Support).

Guest Support

A Scale Function written in Rust often looks something like this:

scale.rs
use scale_signature_http::context::Context;

pub fn scale(ctx: &mut Context) -> Result<&mut Context, Box<dyn std::error::Error>> {
    ctx.response().set_body("Hello, World!".to_string());
    Ok(ctx)
}

The above example is a simple HTTP Function that responds with “Hello, World!” to any request.

By default, the generated function will be configured to use the HTTP Signature, which provides an interface for handling HTTP requests and responses. To learn more about the HTTP Signature and the interfaces it provides, you can check out the HTTP Signature Reference. Learn more about Signatures in the Signatures Overview.

Compiling these Functions requires the appropriate toolchain to be installed on your machine.

Installing the Rust Toolchain

To use Rust as the Guest Language, you'll need to install the following:

The best way to install Rust is to follow the official instructions for your operating system and platform at https://www.rust-lang.org/tools/install.

In general, you'll want to install the rustup tool, which will allow you to easily install and manage multiple versions of Rust on your machine. This can be done by running the following command:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

You can verify that Rust was installed correctly by running the following command:

rustc --version

The minimum supported version of Rust for use with Scale Functions is 1.67.0.

You can verify that Cargo was installed correctly by running the following command:

cargo --version

The minimum supported version of Cargo for use with Scale Functions is 1.67.0.

Next, you'll need to install the wasm32-unknown-unknown build target. This can be done by running the following command:

rustup target add wasm32-unknown-unknown

You can verify that the build target was installed correctly by running the following command and verifying that wasm32-unknown-unknown is listed in the output:

rustup target list --installed