Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Unified Modeling Language (UML) class diagram generator for Solidity contracts.
The following installation assumes Node.js has already been installed which comes with Node Package Manager (NPM).
To install globally so you can run sol2uml
from anywhere
npm link sol2uml --only=production
To see the usage options
$ sol2uml -h
Usage: sol2uml [options] <file or root folder>
Generates UML diagrams from Solidity source code
Options:
-v, --verbose With debugging statements
-f, --outputFormat [value] Output file format: svg, png, dot or all (default: "svg")
-n, --outputFileName [value] Output file name
-c, --clusterFolders Cluster contracts into source folders
-h, --help output usage information
To generate the test contracts in this repo
$ sol2uml.js ./src/contracts
To generate a SVG diagram of all Solidity files under some root folder and output the svg file to a specific location
$ sol2uml.js path/to/contracts/root/folder -n ./outputFile.svg
To generate a diagram of all contracts in a single Solidity file, the output file in png format to output file ./someFile.png
$ sol2uml.js path/to/contracts/root/folder/solidity/file.sol -f png -n ./someFile.png
To generate SVG and PNG diagrams of all Solidity files under some root folder. The output will be diagram.svg
and diagram.png
files in the working folder.
$ sol2uml.js ./contracts -f all -v
Open Zeppelin's ERC20 token contracts Generated from version 2.3.0
See examples for more diagrams.
Good online resources for learning UML
A Solidity variable becomes an attribute in UML and a Solidity function becomes an operation in UML.
The most concise explanation of the What is the difference between association, aggregation and composition.
The following UML relationships are used in Solidity terms:
A
has a storage variable of contract or interface B
. The variable will exist beyond the transaction in the smart contract.A
has a memory variable of class B
. This can be a function parameter, return parameter or function variable. The variable will no longer exist beyond the transaction.A
inherits from contract, interface or abstract contract B
Note a class in the above can also be an Interface, Abstract class or Library.
This is a rewrite of the Richard Ramos's solidity-diagram-gen tool which no longer works as it uses solidity-parser which cannot handle newer Solidity syntax like constructor
.
This version uses the solidity-parser-antlr Solidity parser which is built on top of ANTLR4 grammar. The logic to generate the dot syntax has been rewritten and different UML syntax is now used.
The diagrams are generated using viz.js which uses Graphviz to render a Scalable Vector Graphics (SVG) file. Graphviz Online allows dot files to be edited and rendered into a SVN dynamically.
FAQs
Solidity contract visualisation tool.
The npm package sol2uml receives a total of 2,564 weekly downloads. As such, sol2uml popularity was classified as popular.
We found that sol2uml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.