• Stars
    star
    362
  • Rank 117,671 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ethereum transaction visualizer. Generates UML sequence diagram for a transaction's contract calls.

UML for Ethereum Transactions

npm (tag) Twitter Follow

Unified Modeling Language (UML) sequence diagram generator for Ethereum transaction.

The following contract call and value transfer diagrams are for the Uniswap V1 transaction 0xe5e35ee13bb6326df4da89f17504a81923299d4986de06a019ca7856cbe76bca that removes MKR liquidity from the Uniswap V1 MKR pool.

Contract Call Diagram

Contract call example

See a lot more call diagram examples with different options here.

Value Transfer Diagrams

Value transfer example

More value transfer diagram examples can be found here.

Install

The following installation assumes Node.js has already been installed which comes with Node Package Manager (NPM).

tx2uml needs Java installed as that's required by PlantUML to generate the diagrams.

To install globally so you can run tx2uml from anywhere

npm link tx2uml --only=production

To upgrade run

npm install tx2uml -g

Usage

Command Line Interface (CLI)

Use the -h option to see the tx2uml CLI usage options

Usage: tx2uml [command] <options>

Ethereum transaction visualizer that generates UML sequence diagrams from an Ethereum archive node and Etherscan like
block explorer

Options:
  -f, --outputFormat <value>    output file format (choices: "png", "svg", "eps", "puml", default: "svg")
  -o, --outputFileName <value>  output file name. Defaults to the transaction hash
  -u, --url <url>               URL of the archive node with trace transaction support (default: "http://localhost:8545", env: ARCHIVE_NODE_URL)
  -c, --chain <value>           blockchain explorer network to get source code from (choices: "mainnet", "goerli", "sepolia", "arbitrum", "optimisim", "polygon", "avalanche", "bsc", "crono", "fantom", "gnosis",
                                "moonbeam", default: "mainnet", env: ETH_NETWORK)
  -cf, --configFile <value>     name of the json configuration file that can override contract details like name and ABI (default: "tx.config.json")
  -m, --memory <gigabytes>      max Java memory of PlantUML process in gigabytes. Java default is 1/4 of physical memory. Large txs in png format will need up to 12g. svg format is much better for large transactions.
  -v, --verbose                 run with debugging statements (default: false)
  -V, --version                 output the version number
  -h, --help                    display help for command

Commands:
  call [options] <txHash(s)>    Generates a UML sequence diagram of transaction contract calls between contracts (default).
  value <txHash(s)>             Generates a UML sequence diagram of token and ether value transfers between accounts and contracts. This requires an archive node that supports debug_traceTransaction with custom EVM tracers which are Geth, Erigon or Anvil.
  copy [options] <txHash(s)>    Copies one or more transactions from one chain to another. This is either relayed with the original signature or impersonated with a different signer.
  help [command]                display help for command

Call command

Usage: tx2uml call <txhash(s)> [options]

Generates a UML sequence diagram of transaction contract calls between contracts (default).

Arguments:
  txHash(s)                   transaction hash or an array of hashes in hexadecimal format with a 0x prefix. If running for multiple transactions, the comma-separated list of transaction hashes must not have white spaces

Options:
  -n, --nodeType <value>      type of Ethereum node the provider url is pointing to. This determines which trace API is used (choices: "geth", "erigon", "nether", "openeth", "tgeth", "besu", "anvil", default: "geth", env: ARCHIVE_NODE_TYPE)
  -k, --etherscanKey <value>  Etherscan like block explorer API key
  -a, --noAddresses <value>   hide calls to contracts in a list of comma-separated addresses with a 0x prefix
  -d, --depth <value>         limit the transaction call depth
  -e, --noEther               hide ether values (default: false)
  -g, --noGas                 hide gas usages (default: false)
  -l, --noLogDetails          hide log details emitted from contract events (default: false)
  -p, --noParams              hide function params and return values (default: false)
  -t, --noTxDetails           hide transaction details like nonce, gas and tx fee (default: false)
  -x, --noDelegates           hide delegate calls from proxy contracts to their implementations and calls to deployed libraries (default: false)
  -h, --help                  display help for command

Value command

Usage: tx2uml value <txhash(s)> [options]

Generates a UML sequence diagram of token and ether value transfers between accounts and contracts. This requires an archive node that supports debug_traceTransaction with custom EVM tracers which are Geth, Erigon or Anvil.

Arguments:
  txHash(s)   transaction hash or an array of hashes in hexadecimal format with a 0x prefix. If running for multiple transactions, the comma-separated list of transaction hashes must not have white spaces

Options:
  -e, --onlyToken  get transfers only from token events. No ETH transfers will be included. Use when provider does not
                   support debug_traceTransaction with custom tracer. (default: false)
  -h, --help       display help for command

Copy command

Usage: tx2uml copy <txhash(s)> [options]

Copies one or more transactions from one chain to another. This is either relayed with the original signature or
impersonated with a different signer.

Arguments:
  txHash(s)                    transaction hash or an array of hashes in hexadecimal format with a 0x prefix. If
                               running for multiple transactions, the comma-separated list of transaction hashes must
                               not have white spaces

Options:
  -du, --destUrl <url>         url of the node provider the transaction is being copied to (default:
                               "http://localhost:8545", env: DEST_NODE_URL)
  -i, --impersonate <address>  Address of the account that is to be impersonated. This only works for development nodes
                               like Hardhat and Anvil. The default is the transaction is relayed so is from the
                               original signer.
  -h, --help                   display help for command

Configuration file

You can use a config file to set contract properties that are not available on chain or on Etherscan. For example, the contract's name and protocol. The config file can also be used to supply contract ABIs if a contract has not been verified on Etherscan. This is particularly useful if you are testing on a local fork of mainnet and some of the contracts in the transaction are yet to be deployed on mainnet.

The config file is in json format and has json schema config.schema.json. The config file is an object with an address property for each contract.

The default file is tx.config.json in the current working folder, but you can set the location and name of the config file with the -cf, --configFile <value> option.

An example config file

{
  "0xd6ed651CfDf7778794649FfA87557EF091DfFE81": {
    "protocolName": "mStable",
    "contractName": "Convex3CrvVault",
    "tokenSymbol": "mv3CRV",
    "tokenName": "Convex 3Crv Vault",
    "abi": [
      ...
    ]
  },
  "0xaF94d5585CCCb04afcf98cA49E60F09f96f6444d": {
    "protocolName": "mStable",
    "contractName": "CurveMetapoolCalculatorLibrary"
  }
}

Call Sequence Syntax

Syntax

Participants

The participant names are shortened contract addresses. Basically, the first and last 2 bytes in hexadecimal format with a 0x prefix.

Stereotypes are added for the contract and token name if they can be sourced. The contract name comes from Etherscan's verified contracts.

Messages

There are five types of messages

  • Call is a solid or dotted line with a filled arrow head at the to contract.
  • Return is a dotted line with a filled arrow head at the from contract.
  • Delegate is a solid or dotted line with an open arrow head at the to contract.
  • Create is a filled line with a filled arrow head and a circle at the contract being created.
  • Selfdestruct is a solid line with a half filled arrow head looping back on itself with a Self-Destruct label.

Call and delegate messages with a dotted line are proxy calls that uses the calling contract's fallback function.

Delegate Calls

A delegatecall allows code to be executed on a contract in the context of the calling contract. That is, the delegated code appears as if it is running on the caller's contract. This means it has access to the caller's storage, Ether and calls will appear to come from the caller. Examples of delegate calls are proxy contracts calling their implementations or calls to library contracts.

In the sequence diagram, the lifeline of the delegated call will be in blue and calls will come from the calling contract. In the below example, the third call is the delegate call to the 0x3333..4444 contract. Although the code is executed on the 0x3333..4444 contract, the context is from 0x2222..3333 so the two calls to 0x4444..5555 are shown in blue and are from 0x2222..3333.

The -x or --noDelegates option can be used to hide all delegate calls.

Delegate example

Data Source

Archive node that supports tracing transactions

tx2uml needs an Ethereum archive node that supports the debug_traceTransaction or trace_transaction JSON RPC APIs.

The ethereum node url can be set with the -u or --url options or by exporting the ARCHIVE_NODE_URL environment variable. For example

export ARCHIVE_NODE_URL=https://api.archivenode.io/<your API key>/turbogeth 

Known Ethereum node clients that support debug_traceTransaction with a tracer parameter are:

tx2uml will use --nodeType geth as it's default option.

You can test if your node supports debug_traceTransaction with the following curl command

curl --location --request POST 'https://your.node.url/yourApiKey' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc":"2.0",
    "method":"debug_traceTransaction",
    "params":["0xe5e35ee13bb6326df4da89f17504a81923299d4986de06a019ca7856cbe76bca", {"tracer": "callTracer"}],
    "id":1
}'

Anvil, Hardhat and Genache all support debug_traceTransaction but without the tracer parameter so will not work with tx2uml.

Known Ethereum node clients that support trace_transaction are:

You can test if your node supports trace_transaction with the following curl command

curl --location --request POST 'https://your.node.url/yourApiKey' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc":"2.0",
    "method":"trace_transaction",
    "params":["0xb2b0e7b286e83255928f81713ff416e6b8d0854706366b6a9ace46a88095f024"],
    "id":1
}'

Ethereum client trace support

OpenEthereum Nethereum Besu Geth Erigon Akula Anvil Hardhat Ganache
trace_replayTransaction X X X X
trace_transaction X X X X X
trace_rawTransaction X X X X
debug_traceTransaction X X X X X X X
debug_traceTransaction with tracer param X X

Ethereum API provider trace support

ArchiveNode Alchemy QuickNode Chainstack GetBlock WatchData Infura
trace_transaction X X X X X X
debug_traceTransaction X X X X
debug_traceTransaction call tracer X X X X
debug_traceTransaction custom tracer X X X

Most Ethereum API providers do not provide tracing or debugging APIs as they are resource intensive on the server side.

Etherscan

Etherscan is used to get the Application Binary Interfaces (ABIs) for the contracts used in a transaction. Etherscan's get contract ABI API is used with module contract and action getsourcecode. For example https://api.etherscan.io/api?module=contract&action=getsourcecode&address=0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413

PlantUML

PlantUML is a Java program that can convert Plant UML syntax into png, svg or eps images. tx2uml pipes the PlantUML to the spawned Java process which then pipes the image outputs to a file.

plantuml.jar version 1.2023.1 under MIT license is currently shipped in the lib folder.

See Recent changes for PlantUML's release notes.

PlantText

PlantText is an online tool that generates diagrams from PlantUML.

PlantUML extension for VS Code

Jebbs PlantUML extension for VS Code is used to authoring the PlantUML diagrams.

Alt-D on Windows, or Option-D on Mac, to stat PlantUML preview in VS Code.

Generate png files form puml

The following will generate png files for the above examples.

java -jar ./lib/plantuml.jar ./examples/syntax.puml ./examples/delegate.puml

UML Syntax

Good online resources for learning UML

Similar Visualisation Tools

Development

Testing

If you want to run all the tests, you'll need to export the following environment variables which are used by the tests to connect to different archive nodes. If you are using Archive Node, you need to replace with the API key provided to you.

export ARCHIVE_NODE_URL=https://api.archivenode.io/<your api key>/nethermind
export NETHERMIND_URL=https://api.archivenode.io/<your api key>/nethermind
export ERIGON_GETH_URL=https://api.archivenode.io/<your api key>/erigon
npm run test

Note two of the tests are currently failing due to bugs TurboGeth and Nethermind bugs.

Publishing

npm build and publish commands

npm run prettier:fix
npm run clean
npm run package-lock
npm run build
# make tx2uml globally available for local testing
npm link
# check all the files are included in the npm package
npm pack --dry-run
npm publish

More Repositories

1

eth-scratch3

Scratch 3 extensions for Ethereum contracts
JavaScript
60
star
2

btc-markets

BTC Markets Javascript API client
TypeScript
34
star
3

okcoin

Node.js API wrapper to the OKCoin bitcoin exchange
JavaScript
22
star
4

open-bank-token

An Ethereum ERC20 token contract that is connected to a bank account via an Open Bank Project API.
TypeScript
16
star
5

promievent

A promise that can emit events
TypeScript
9
star
6

eth-scratch

ScratchX extension for connecting to the Ethereum blockchain and ERC20 token contracts
JavaScript
8
star
7

uniswap-v4-hooks

A playground for Uniswap v4 hooks
Solidity
7
star
8

independentreserve

Independent Reserve Javascript API client
JavaScript
6
star
9

itbit

itbit API client for node.js
JavaScript
6
star
10

crypto-beasts

Blockchain-base card game built using Scratch and Loom for EDCON 2019 Hackathon
JavaScript
5
star
11

token-info

Gets symbol and name properties from Ethereum token (ERC20) contracts
TypeScript
4
star
12

defi-anime

ETH Tokyo hackathon project animating a Uniswap V3 pool over time
TypeScript
4
star
13

digital-dollar-technical-workshops

A series of workshops to address the technical challenges of issuing a digital dollar on a Blockchain
4
star
14

btc-china

Node.js wrapper to BTCC's API
JavaScript
3
star
15

ethereum-programmable-money

Library of smart contract to program Ethereum tokens
3
star
16

abstract-accounts

A playground for ERC-4337 Account Abstraction
Solidity
3
star
17

digital-dollar-ethereum

An Ethereum implementation of a Digital Dollar
JavaScript
2
star
18

immutable-events

Smart contract to make key-value data immutable
TypeScript
2
star
19

web3-jest

Simple test of web3.js using the Jest testing framework
JavaScript
1
star
20

exchange-visualisation

HTML
1
star
21

node-imports

An example Node.js program using TypeScript to show module imports and type definitions
JavaScript
1
star