CLVM Tools

0.4.10 · active · verified Fri Apr 17

clvm-tools is the official compiler for CLVM (Chia Lisp Virtual Machine) programs. It provides utilities for assembling CLVM code from a higher-level Lisp-like syntax, disassembling compiled code, and running CLVM programs. The current version is 0.4.10, and the library is actively maintained with frequent minor releases to support new Python versions and improve compatibility with the broader Chia ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to compile a basic CLVM program using `assemble` and then execute it using `brun`. It shows how to pass arguments to the CLVM program and interpret the result. For production use, consider installing `clvm-tools` with the `clvm_rs` extra for performance.

from clvm_tools.binutils import assemble, brun
from clvm.Program import Program

# A simple CLVM program that adds 1 to its argument
clvm_source_code = "(mod (A) (+ A 1))"

# Compile the CLVM source code
compiled_program_bytes = assemble(clvm_source_code)
print(f"Compiled CLVM (hex): {compiled_program_bytes.hex()}")

# Define the arguments for the program (e.g., A = 5)
program_arguments = Program.to((5,))

# Run the compiled program with the arguments
# `brun` can leverage clvm_rs if installed for better performance.
result = brun(compiled_program_bytes, program_arguments)

print(f"Result of program with A=5: {result.as_int()}")

view raw JSON →