CLVM-rs

0.17.5 · active · verified Wed Apr 15

CLVM-rs is a Rust-based implementation of the Chialisp Virtual Machine (CLVM) for the Chia Network's cryptocurrency, designed for enhanced security and performance. It provides Python bindings allowing developers to interact with the CLVM's core functionalities. Currently at version 0.17.5, the library maintains an active development pace with frequent updates and improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to assemble a simple Chialisp program, create a `Program` object, and execute it using `run_program`. It shows basic program evaluation and result retrieval. Note that `assemble` is usually part of `clvm_tools_rs` or `clvm_tools`, but often used in conjunction with `clvm_rs`.

from clvm_rs.program import Program
from clvm_rs.api import run_program, CLVM_COST_RATIO_DEFAULT
from clvm_rs.clvm_tools.binutils import assemble

# A simple CLVM program: (q . 1) which quotes the atom 1
program_code = '(q . "hello")'
program = Program.fromhex(assemble(program_code).hex())

# An empty argument list (nil)
args = Program.null()

# Set flags for evaluation (e.g., MEMPOOL_MODE)
# For a simple run, default flags are often sufficient
flags = 0 # No special flags for this simple example

try:
    # Run the program with a default cost ratio
    cost, result = run_program(program, args, flags, CLVM_COST_RATIO_DEFAULT)
    print(f"Program executed successfully. Cost: {cost}")
    print(f"Result: {result.as_python()}")
except Exception as e:
    print(f"Error executing program: {e}")

view raw JSON →