Skip to content

DamlForge

Write Daml smart contracts for Canton in Python syntax.

DamlForge lets you write Canton smart contracts in .vy files. These use Python syntax with a few contract-specific (Vyper-flavored) keywords. The forge compiler turns each .vy file into ordinary Daml source, and DPM, the Daml package manager, builds, tests, and ships that source. Nothing in a .vy file runs as Python: the file is parsed, checked, and lowered straight to Daml.

1. Install DamlForge (Python 3.11 or newer):

Terminal window
pip install damlforge

2. Write a contract in Main.vy:

from forge.builtins.daml_lang import create
from forge.models import ContractId, Party, choice, template
@template
class Asset:
issuer: Party
owner: Party
name: str
signatory: Party = issuer
observer: Party = owner
ensure: bool = name != ""
@choice(controller=owner, consuming=True)
def give(self, new_owner: Party) -> ContractId[Asset]:
return create(Asset(issuer=self.issuer, owner=new_owner, name=self.name))

3. Compile it to Daml:

Terminal window
forge daml Main.vy -o out/

forge generates out/Main.daml:

module Main where
template Asset
with
issuer : Party
owner : Party
name : Text
where
signatory issuer
observer owner
ensure name /= ""
choice Give : ContractId Asset
with
new_owner : Party
controller owner
do
let self = this
create (Asset with issuer = self.issuer, owner = new_owner, name = self.name)

More: see the full documentation, from setup to packaging.