• Home
  • Readings
  • Github
  • MIES
  • TmVal
  • About
Gene Dan's Blog

Monthly Archives: December 2014

You are browsing the site archives by month.

No. 114: Visualizing the Blockchain

24 December, 2014 5:29 PM / Leave a Comment / Gene Dan

For those of you who don’t know what Bitcoin is, it’s a digital currency that’s been gaining attention over the last few years, mostly due to its obscure user base, popularity on the black market (although most bitcoin transactions are legal), and its exchange rate volatility versus the U.S. dollar.

I’ve been interested in Bitcoin for quite some time, since unlike cash transactions, all bitcoin transactions are recorded on a publicly available ledger called the Blockchain. Because the blockchain records all transactions that occur over the bitcoin network, it can be a valuable source of information, revealing interesting patterns about peer-to-peer monetary transactions that were previously unavailable under traditional currency, due to lack of available data.

I stumbled across some CSV files on the internet that contain parsed blockchain information available in a script-friendly format here. Using this dataset I wrote a script to extract the transactions from the first 500 bitcoin users:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#import dataset
#edges <- read.csv("user_edges.txt", header=FALSE)
#head(edges)
 
###subset first n users
lim <- 500
edges.sub <- edges[edges$V2 <= lim & edges $V3 <= lim & (edges$V2 != edges$V3), c("V2","V3")]
head(edges.sub,500)
sub.unique <- edges.sub[!duplicated(edges.sub),]
sub.unique$edgenum <- 1:nrow(sub.unique)
head(sub.unique)
sub.unique$edges <- paste('<edge id="', as.character(sub.unique$edgenum),'" source="', sub.unique$V2, '" target="',sub.unique$V3, '"/>',sep="")
 
###build nodes
nodes <- data.frame(id=sort(unique(c(sub.unique$V2,sub.unique$V3))))
nodes$nodestr <- paste('<node id="', as.character(nodes$id), '" label="',nodes$id, '"/>',sep="")
head(nodes)
 
### build metadata
gexfstr <- '<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns:viz="http:///www.gexf.net/1.1draft/viz" version="1.1" xmlns="http://www.gexf.net/1.1draft">
<meta lastmodifieddate="2010-03-03+23:44">
<creator>Gephi 0.7</creator>
</meta>
<graph defaultedgetype="undirected" idtype="string" type="static">'
 
 
### append nodes
gexfstr <- paste(gexfstr,'\n','<nodes count="',as.character(nrow(nodes)),'">\n',sep="")
fileConn<-file("output.gexf")
for(i in 1:nrow(nodes)){
  gexfstr <- paste(gexfstr,nodes$nodestr[i],"\n",sep="")}
gexfstr <- paste(gexfstr,'</nodes>\n','<edges count="',as.character(nrow(sub.unique)),'">\n',sep="")
 
### append edges and print to file
for(i in 1:nrow(sub.unique)){
  gexfstr <- paste(gexfstr,sub.unique$edges[i],"\n",sep="")}
gexfstr <- paste(gexfstr,'</edges>\n</graph>\n</gexf>',sep="")
writeLines(gexfstr, fileConn)
close(fileConn)

I subsequently imported the output file into gephi to create a network visualization of the transactions. You can view the process in the video below.

https://www.youtube.com/watch?v=wjw0ksaRSO4&feature=youtu.be

The resulting graph:

Transactions amongst the first 500 users of Bitcoin

Transactions amongst the first 500 users of Bitcoin

Here you can see that the modularity algorithms have identified clusters of tightly-knit users who transact frequently with each other, along with influential users who may be running businesses or may be serving as middlemen between other groups of users.

Posted in: Logs, Mathematics / Tagged: bitcoin, blockchain, graph, network

Archives

  • September 2023
  • February 2023
  • January 2023
  • October 2022
  • March 2022
  • February 2022
  • December 2021
  • July 2020
  • June 2020
  • May 2020
  • May 2019
  • April 2019
  • November 2018
  • September 2018
  • August 2018
  • December 2017
  • July 2017
  • March 2017
  • November 2016
  • December 2014
  • November 2014
  • October 2014
  • August 2014
  • July 2014
  • June 2014
  • February 2014
  • December 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • March 2013
  • January 2013
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • January 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • September 2009
  • August 2009
  • May 2009
  • December 2008

Categories

  • Actuarial
  • Cycling
  • Logs
  • Mathematics
  • MIES
  • Music
  • Uncategorized

Links

Cyclingnews
Jason Lee
Knitted Together
Megan Turley
Shama Cycles
Shama Cycles Blog
South Central Collegiate Cycling Conference
Texas Bicycle Racing Association
Texbiker.net
Tiffany Chan
USA Cycling
VeloNews

Texas Cycling

Cameron Lindsay
Jacob Dodson
Ken Day
Texas Cycling
Texas Cycling Blog
Whitney Schultz
© Copyright 2025 - Gene Dan's Blog
Infinity Theme by DesignCoral / WordPress