sol2seq
A Rust library and CLI tool for generating sequence diagrams from Solidity smart contracts.
Features
- Generate Mermaid sequence diagrams from Solidity AST JSON files
- Process Solidity source files directly
- Supports both solc-generated and Aderyn-generated AST formats
- Visualize contract interactions, function calls, and events
- Customize diagram appearance with light/dark themes
- Use as a library in your Rust projects or as a CLI tool
Installation
# As a CLI tool
# Or from source
CLI Usage
# Generate a sequence diagram from Solidity source files directly
# Generate a sequence diagram from an AST JSON file
# Generate with lighter colors
Command-Line Arguments
Usage: sol2seq [OPTIONS] <COMMAND>
Commands:
source Generate diagram from Solidity source files
ast Generate diagram from AST JSON file
help Print this message or the help of the given subcommand(s)
Options:
-l, --light-colors Use lighter colors for the sequence diagram
-h, --help Print help information
-V, --version Print version information
Source Command
Usage: sol2seq source [OPTIONS] <SOURCE_FILES>... [OUTPUT_FILE]
Arguments:
<SOURCE_FILES>... Solidity source files to process
[OUTPUT_FILE] Output file path (optional, will print to stdout if not provided)
Options:
-l, --light-colors Use lighter colors for the sequence diagram
-h, --help Print help information
AST Command
Usage: sol2seq ast [OPTIONS] <AST_FILE> [OUTPUT_FILE]
Arguments:
<AST_FILE> AST JSON file path
[OUTPUT_FILE] Output file path (optional, will print to stdout if not provided)
Options:
-l, --light-colors Use lighter colors for the sequence diagram
-h, --help Print help information
Generating AST JSON
If you prefer to generate the AST JSON manually and then use it with sol2seq, you can use one of the following methods:
Using Solidity Compiler
# Generate AST JSON for a Solidity file
# Then use sol2seq to generate a sequence diagram
Using Aderyn
sol2seq also supports the AST format generated by Aderyn:
# Generate AST using Aderyn
# Then use sol2seq with the Aderyn-generated AST
Library Usage
use Result;
use ;
API Reference
The library provides the following main functions:
generate_diagram_from_file
Generates a sequence diagram from an AST JSON file.
Parameters:
ast_file: Path to the AST JSON file.config: Configuration for diagram generation.
Returns:
- The generated diagram as a string.
generate_diagram_from_sources
Generates a sequence diagram directly from Solidity source files.