Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mermaider

Mermaider is a Python tool that generates class diagrams for smart contracts written in Solidity.

Quickstart

solc                                                                  \
  /home/someone/path/to/my/Contract.sol                               \
  '@openzeppelin=/home/someone/path/to/my/node_modules/@openzeppelin' \
  --combined-json ast >/tmp/artifacts.json

git clone git@github.com:ydm/mermaider.git
cd mermaider
python main.py </tmp/artifacts.json

Example

contract Hello {
    uint256 public world;
    function Mermaider() public {}
    event Generates(uint256 these, uint256 diagrams);
    function Out() external {}
    function Of() internal {}
    function Solidity() private {}
    struct Smart {
        uint256 contracts;
    }
}

gets turned into

classDiagram
class `Hello` {
    +uint256 world
    +Mermaider()
    event Generates(these, diagrams)
    +Out()
    #Of()
    -Solidity()
}
`Hello` ..> `Hello.Smart`
class `Hello.Smart` {
    <<struct>>
    -uint256 contracts
}
Loading

For a more complex example, check UniswapV3Pool.

Usage

  • This project has no external Python dependencies.
  • Expected input is solc ^0.8 ASTs.
solc                                                                  \
  /home/someone/path/to/my/Contract.sol                               \
  '@openzeppelin=/home/someone/path/to/my/node_modules/@openzeppelin' \
  --combined-json ast >/tmp/artifacts.json

git clone git@github.com:ydm/mermaider.git
cd mermaider
python main.py </tmp/artifacts.json

Optional dependencies

If eth-hash is installed, function signatures (as displayed in the diagram) will be additionally hashed and checked against the compiled function selectors.

python -m venv env
source env/bin/activate
python -m pip install --upgrade pip
python -m pip install eth-hash[pycryptodome]
python main.py

TODOs

About

Generate Mermaid class diagrams for Solidity contracts

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages