Skip to content

Instantly share code, notes, and snippets.

@traderbagel
Last active July 21, 2018 12:25
Show Gist options
  • Save traderbagel/c3b2f691b98a9009fcb69edd92f4422e to your computer and use it in GitHub Desktop.
Save traderbagel/c3b2f691b98a9009fcb69edd92f4422e to your computer and use it in GitHub Desktop.
build graph from transactions
from collections import defaultdict
from decimal import Decimal
import networkx as nx
edges = defaultdict(lambda :defaultdict(Decimal))
for tx in eth_transactions:
edges[tx.from_address][tx.to_address] += tx.amount
G = nx.DiGraph()
G.add_weighted_edges_from([(f, t, edges[f][t]) for f
in edges for t in edges[f] if edges[f][t] > Decimal(100)])
print(nx.info(G))
''' Output
Name:
Type: DiGraph
Number of nodes: 349
Number of edges: 296
Average in degree: 0.8481
Average out degree: 0.8481
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment