CLVM-rs
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
- breaking Starting from version 0.17.2, clvm_rs requires Python 3.10 or newer. Projects on older Python versions will need to upgrade their Python environment or use an older clvm_rs version.
- breaking The `intern` function was renamed to `intern_tree` in version 0.17.3 as part of `CHIA-3823`. Code calling the old `intern` function will break.
- gotcha Version 0.16.5 introduced stricter mempool rules and fixed edge cases in `is_canonical_serialization()`. This may lead to previously accepted, non-canonical CLVM programs or transactions being rejected by the mempool.
Install
-
pip install clvm-rs
Imports
- Program
from clvm_rs.program import Program
- run_program
from clvm_rs.api import run_program
Quickstart
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}")