#20 Network analysis
Preface
All public blockchains are essentially large networks. Analyzing Onchain data most likely involves network analysis. The existing visualizations on common data platforms like Dune currently have difficulty describing the relationships between nodes on blockchains.
Let's use the controversial FTX "hacker" address (0x59ABf3837Fa962d6853b4Cc0a19513AA031fd32b) as an example to do some network analysis (we won't debate whether it's a hacker or the Panama government). We'll look at where the ETH from this address went (we'll examine the 2-hop relationships outgoing from this address).
Tools used in the process:
Dune: get raw data between addresses and do initial processing
Python
Networkx: python package for creating, manipulating and studying complex networks. Allows storing networks in standardized and non-standardized data formats, generating various random and classic networks, analyzing network structure, building network models, designing new network algorithms, drawing networks, etc.
More info: https://networkx.org/
Plotly: great package for visualizations, can generate interactive HTML files. Has a complementary frontend framework called DASH that is very user-friendly for data analysts without advanced engineering skills.
More info: https://plotly.com/
Pandas: most commonly used Python package for working with data, provides many functions and methods to enable quick and convenient data manipulation.
More info: https://pandas.pydata.org/
Etherscan API: calculating ETH Balance on Dune is too tedious, requiring pulling all data each time. We can simply get Balance from the Etherscan API.
Overview
The process can be broadly divided into the following steps:
Get raw data from Dune
Process relationships between nodes and handle various attribute data needed for drawing the network graph (pos, label, color, size etc.) using Networkx
Visualize the network graph using Plotly
Detailed process
I. Get Raw Data from Dune (SQL Part)
The SQL is quite complex so I won't go into detail, so feel free to check the URL for details if interested:
Get data with relationships between all relevant addresses with SQL: https://dune.com/queries/1753177
from: sender of the transaction
to: receiver of the transaction
transfer_eth_balance: total ETH transferred between two
transfer_eth_count: total number of ETH transfers between two accounts
Get list of all addresses and associated labels via SQL: https://dune.com/queries/2430347
address: all addresses involved in this network analysis
level_type: level in the network for all addresses involved (Core, Layer One, Layer Two)
account_type: is a regular EOA, exchange, or smart contract
label: useful aggregated info for the address into a label for subsequent visualization in python
II. Read local files into DataFrames using pandas and supplement with Balance column from Etherscan API
Download Dune data locally (either via Dune API or copy-paste) and read into pandas from local files
Get Balance data for all addresses via Etherscan API and write to DataFrame
Add Balance to DataFrame, create Balance_level column (label based on Balance size) to control Node size in network graph later
III. Define a function to process node relationships with NetworkX and draw with Plotly
IV. Call the drew_graph function, pass in the 2 DataFrames to draw the graph. Export as HTML file.
V. Result graph
Check out the interactive version at this URL: https://pro0xbi.github.io/FTX_Accounts_Drainer.html
Node colors
Green is the FTX "hacker" address
Blue are normal EOA accounts that had large transfers (>100ETH) with it
Yellow are Exchange addresses (FTX)
Red are smart contract addresses
Node size
Larger nodes indicate larger balances for that address. The largest nodes have balances >10,000 ETH
We can see that among all addresses associated with the FTX "hacker", there are still at least 12 addresses holding >10,000 ETH, meaning at least 120,000 ETH have not been sold by the "hacker".
About Us
Sixdegree
is a professional onchain data analysis team Our mission is to provide users with accurate onchain data charts, analysis, and insights. We are committed to popularizing onchain data analysis. By building a community and writing tutorials, among other initiatives, we train onchain data analysts, output valuable analysis content, promote the community to build the data layer of the blockchain, and cultivate talents for the broad future of blockchain data applications. Welcome to the community exchange!
Website: sixdegree.xyz
Email: contact@sixdegree.xyz
Twitter: twitter.com/SixdegreeLab
Dune: dune.com/sixdegree
Github: https://github.com/SixdegreeLab
Last updated