CLVM Tools Rust

0.4.0 · active · verified Wed Apr 15

clvm-tools-rs provides a Rust implementation of tools for working with the Chialisp language, including a compiler and REPL, with Python and WebAssembly (WASM) bindings. It is a port of the original clvm_tools to Rust, aiming for improved performance and better alignment with the underlying clvm_rs Rust implementation. The library is actively developed, with its core Rust components seeing frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `compile_clvm` from `clvm_tools_rs` to compile a Chialisp source file into its CLVM hexadecimal representation. It creates a simple Chialisp program, compiles it, and prints the result.

import os
from pathlib import Path
from clvm_tools_rs import compile_clvm

# Create a dummy Chialisp file
chialisp_code = """ (mod (A B)
    (+ A B)
) """

# Ensure a temporary directory exists for the output
output_dir = Path("temp_chialisp_output")
output_dir.mkdir(exist_ok=True)

chialisp_file_path = output_dir / "my_program.clsp"
compiled_file_path = output_dir / "my_program.clvm.hex"

with open(chialisp_file_path, "w") as f:
    f.write(chialisp_code)

# Compile the Chialisp code
# The compile_clvm function expects strings for paths
compile_result = compile_clvm(str(chialisp_file_path), str(compiled_file_path), [], False)

print(f"Compiled successfully: {compile_result['success']}")
if compile_result['success']:
    print(f"Output CLVM hex written to: {compiled_file_path}")
    with open(compiled_file_path, "r") as f:
        print(f"Compiled CLVM (hex): {f.read().strip()}")
else:
    print(f"Compilation error: {compile_result['error']}")

# Clean up temporary files (optional)
# os.remove(chialisp_file_path)
# os.remove(compiled_file_path)
# os.rmdir(output_dir)

view raw JSON →