Skip to content

Setting Up the Environment

To get started, create a new folder that will hold all the source code.

Next, create two subfolders, one called frontend, and one called backend.

Configuring the backend

The backend is a Rust application that uses the Golem-Base TypeScript SDK to communicate with a running golem-base op-geth node.

Move to the backend folder.

Tip

Here we use Nix and create a flake.nix file and .envrc file to install the Rust tools when you enter the directory. This is optional; if you prfer, you can install the Rust tools manually and globally.

The flake.nix file

Here's the flake.nix file:

{
  description = "A Rust development shell";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
      in
      {
        devShells.default = pkgs.mkShell {
          buildInputs = with pkgs; [
            # Rust toolchain
            rustc
            cargo
            # Common development tools
            clippy
            rustfmt
          ];
        };
      }
    );
}

And here's the .envrc file, just one line:

use flake

After creating these files, you should be promopted with a message about enabling direnv; go ahead and type:

direnv allow

After a few moments, the tools will get installed and will be ready to use. You can verify this by typing:

cargo --version

and you should see a version number.

The Cargo.toml file

Now let's initialize are Cargo.toml file. Type:

cargo init

Now open the Cargo.toml file. You can change the name and version to whatever you like. Copy in the dependencies section from here:

[package]
name = "rust_golembase_media"
version = "0.1.0"
edition = "2024"

[dependencies]
axum = { version = "0.7", features = ["multipart"] }
tokio = { version = "1.0", features = ["full"] }
tower-http = { version = "0.5", features = ["cors"] }
golem-base-sdk = { git = "https://github.com/Golem-Base/rust-sdk.git" }
image = { version = "0.25", default-features = false, features = ["jpeg", "png"] }
serde_json = "1.0"
serde = "1.0"
alloy-primitives = "1.3.1"
hex = "0.4.3"
lazy_static = "1.5.0"
bytes = "1.10.1"
dotenvy = "0.15"
dirs = "6.0"```

Now we're ready to get started!

Head to Step 2.