Visualize your Solidity smart contracts

Bruno Delb
2 min readMay 3, 2022

The design of smart contracts is very sensitive. There must be no vulnerabilities. Security audits are of course the first tool to mitigate the risks. Generating documentation to visualize the control flow of the functions can also help to highlight possible vulnerabilities.

The solgraph (https://www.npmjs.com/package/solgraph) the tool automatically generates a PNG image that is an important piece of documentation.

To simplify its use, we will use a Docker image (devopstestlab/solgraph) that I built.

In first, let’s create a contract MyContract.sol we want to document:

contract MyContract {  uint balance;

function MyContract() {
Mint(1000000);
}

function Mint(uint amount) internal {
balance = amount;
}

function Withdraw() {
msg.sender.send(balance);
}

function GetBalance() constant returns(uint) {
return balance;
}
}

Now, let’s run solgraph:

docker run -it --rm -v $PWD:/data devopstestlab/solgraph

The output lists the smart contracts found:

MyContract.sol

This image parse the current folder ($PWD) to convert each contract (*.sol files). It produces images by adding the .png extension to the contract.

For example, in our example, it produces an image MyContract.sol.png:

--

--

Bruno Delb

Blockchains, DevOps, Agile Coaching, development, testing, Cloud, Management 3.0, ITIL. It defines me.