Starknet Development with Docker: A Streamlined Setup for Cairo Builders

Starknet Development with Docker: A Streamlined Setup for Cairo Builders

Streamlining Cairo Development: A Dockerized Toolkit for Starknet Builders

Developing on Starknet has just got super easy! The Starknet Foundation recently released a Docker image that bundles essential tools for Cairo development into a simple virtual environment. Whether you're a seasoned Starknet developer, hacker (i.e. hackathon builder) or just starting your blockchain journey through BaseCamps, you can spin up a development environment with docker container in minutes and start building.

Tools inside the Docker Image

The docker image is a ready-to-go environment for local Cairo development. It includes:

  1. Scarb – Starknet’s Cairo package manager for efficient project management.

  2. Starkli – The CLI tool to interact with Starknet blockchain and projects.

  3. Starknet Foundry – A suite of developer tools for testing and deploying Cairo contracts.

  4. Rust – A robust programming language crucial for various aspects of Cairo tooling.

  5. Starknet Devnet – A local testnet for testing Starknet smart contracts and dApps.

Prerequisites

Before you begin, ensure you have the following installed:

  • Docker (Install Docker Desktop for Mac/Linux/Windows depending on your operating system)

  • VSCode

  • Dev Containers (Search & install through VSCode’s extension tab)

Setting up Dev Environment

  • Create a directory named sn_workshop

  • Open the above directory in your VSCode (enter code . from terminal)

  • Then create a .devcontainer.json file and populate it with below code:

{
    "name": "dev",
    "image": "starknetfoundation/starknet-dev:2.9.1",
    "customizations": {
        "vscode": {
            "extensions": [
                "StarkWare.cairo1",
                "tamasfe.even-better-toml"
            ]
        }
    }
}
  • Now, before spinning up the container, Linux and Windows (WSL2) users may encounter permission issues. To avoid this, run below command in your terminal. It will ask for password once; everything is smooth sailing after.
sudo usermod -aG docker ${USER}
  • Then go to View -> Command Palette and search for Dev Containers: Rebuild and Reopen in Container.

  • Execute the command, and VSCode will restart in a containerized environment.

  • Give it around 30 minutes or so to cook build. (WSL users might have to wait 6+ hours, don’t worry it’ll work, just provide stable internet throughout the process)

Note: This build process occurs once for each version of starknet-dev image in your .devcontainer.json file. If anything changes in that file, you have to re-build.

  • Congrats! You’re now running VSCode inside the Docker container, with the integrated terminal and environment pre-configured with latest packages for Starknet development.

Next steps

Experiment with Cairo Contracts

  • Start building and testing that awesome idea of yours on Starknet.

  • Use either scarb init to scaffold projects, or git clone <url> to clone a repository you want.

  • Build and run tests with scarb build and scarb test

  • Deploy to Starknet Devnet.

Explore the Docker Repository

  • The image repository includes version details and documentation.

  • Update of packages: Always check the Starknet docker hub for latest configuration (or image) containing latest versions of your packages.

Share Your Feedback

The Starknet community thrives on collaboration. Share your experience, report bugs, or suggest improvements to the image on the official repository.

You can also share any difficulty you are facing here, and we’ll try to respond with a solution as soon we can.