life is too short for a diary




Building and Testing Canton Smart Contracts Locally

Tags: blockchain canton daml makefile

Author
Written by: Tushar Sharma
Featured image for Building and Testing Canton Smart Contracts Locally

Building on Canton requires fast feedback loops. Testing locally before deploying to a testnet saves time and costs. This guide walks through a complete workflow: create a contract, build it, spin up a sandbox, and verify it works via the JSON API.

Step 1: Initialize Your Project

mkdir -p testContract
cd testContract
daml init

This creates the boilerplate:

testContract/
├── daml.yaml         # Project metadata
└── daml/
    └── Main.daml     # Smart contract code

Step 2: Write a Simple Asset Contract

Create daml/Main.daml:

What this does:

Step 3: Build the Contract

daml build

Output:

2026-04-07 20:17:41.33 [INFO] [build]
Created .daml/dist/testContract-1.0.0.dar

The .dar file (DAML ARchive) is like a JAR—it bundles your compiled smart contract.

Step 4: Automate with a Makefile

Create a Makefile at the project root:

Step 5: Run the Sandbox

make start

This builds your contract and spins up:

Step 6: Verify It Works

Test the JSON API health check:

curl http://localhost:7575/readyz

Response:

[+] ledger ok (SERVING)
readyz check passed

Check the version:

curl http://localhost:7575/v2/version

You'll get detailed ledger capabilities. If both curl commands succeed, your sandbox is live.


comments powered by Disqus