WolframAlpha.com
WolframCloud.com
All Sites & Public Resources...
Products & Services
Wolfram|One
Mathematica
Wolfram|Alpha Notebook Edition
Programming Lab
Finance Platform
SystemModeler
Wolfram Player
Wolfram Engine
WolframScript
Enterprise Private Cloud
Enterprise Mathematica
Wolfram|Alpha Appliance
Enterprise Solutions
Corporate Consulting
Technical Consulting
Wolfram|Alpha Business Solutions
Resource System
Data Repository
Neural Net Repository
Function Repository
Wolfram|Alpha
Wolfram|Alpha Pro
Problem Generator
API
Data Drop
Products for Education
Mobile Apps
Wolfram Player
Wolfram Cloud App
Wolfram|Alpha for Mobile
Wolfram|Alpha-Powered Apps
Services
Paid Project Support
Wolfram U
Summer Programs
All Products & Services »
Technologies
Wolfram Language
Revolutionary knowledge-based programming language.
Wolfram Cloud
Central infrastructure for Wolfram's cloud products & services.
Wolfram Science
Technology-enabling science of the computational universe.
Wolfram Notebooks
The preeminent environment for any technical workflows.
Wolfram Engine
Software engine implementing the Wolfram Language.
Wolfram Natural Language Understanding System
Knowledge-based broadly deployed natural language.
Wolfram Data Framework
Semantic framework for real-world data.
Wolfram Universal Deployment System
Instant deployment across cloud, desktop, mobile, and more.
Wolfram Knowledgebase
Curated computable knowledge powering Wolfram|Alpha.
All Technologies »
Solutions
Engineering, R&D
Aerospace & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Mechanical Engineering
Operations Research
More...
Finance, Statistics & Business Analysis
Actuarial Sciences
Bioinformatics
Data Science
Econometrics
Financial Risk Management
Statistics
More...
Education
All Solutions for Education
Trends
Machine Learning
Multiparadigm Data Science
Internet of Things
High-Performance Computing
Hackathons
Software & Web
Software Development
Authoring & Publishing
Interface Development
Web Development
Sciences
Astronomy
Biology
Chemistry
More...
All Solutions »
Learning & Support
Learning
Wolfram Language Documentation
Fast Introduction for Programmers
Wolfram U
Videos & Screencasts
Wolfram Language Introductory Book
Webinars & Training
Summer Programs
Books
Need Help?
Support FAQ
Wolfram Community
Contact Support
Premium Support
Paid Project Support
Technical Consulting
All Learning & Support »
Company
About
Company Background
Wolfram Blog
Events
Contact Us
Work with Us
Careers at Wolfram
Internships
Other Wolfram Language Jobs
Initiatives
Wolfram Foundation
MathWorld
Computer-Based Math
A New Kind of Science
Wolfram Technology for Hackathons
Student Ambassador Program
Wolfram for Startups
Demonstrations Project
Wolfram Innovator Awards
Wolfram + Raspberry Pi
Summer Programs
More...
All Company »
Search
WOLFRAM COMMUNITY
Connect with users of Wolfram technologies to learn, solve problems and share ideas
Join
Sign In
Dashboard
Groups
People
Message Boards
Answer
(
Unmark
)
Mark as an Answer
GROUPS:
Economics
Graphs and Networks
Wolfram Language
Wolfram High School Summer Camp
3
Egor Bugaev
[WSC20]: Creating graphs of Bitcoin transactions
Egor Bugaev
Posted
10 months ago
1275 Views
|
0 Replies
|
3 Total Likes
Follow this post
|
Abstract
Bitcoin transactions transfer currency from a set of inputs to a set of outputs, recording the information into blockchain. In this project, my goal was to create a graph with Bitcoin inputs, outputs, and transactions as vertices, which is useful to analyze where the money came from and how they were spent.
Hashing transactions' inputs and outputs
In order to make transactions and outputs easily distinguishable, I wrote several functions that convert an output or an input into a unique id. Since an output later becomes an input for another transaction, this ID should be possible to get both from the input and from the output. The two parameters that are shared between an output and its later “reincarnation” as an input are transaction ID (where it was created) and input/output address, I concatenated them to create the hash of an input/output.
However, it’s important to specifically tackle the case when the output hasn’t been spent, because than there is no address. In this case, I concatenated transactionID and ScriptString, which is a unique parameter, to create a hash. We cannot use this way for all cases because ScriptString is available only for an output, so to use it we need to be sure that the output hasn’t been spent.
Get output hash from TransactionID and output:
g
e
t
O
u
t
p
u
t
H
a
s
h
[
t
r
a
n
s
a
c
t
i
o
n
_
,
o
u
t
p
u
t
_
]
:
=
B
l
o
c
k
[
{
x
}
,
x
=
t
r
a
n
s
a
c
t
i
o
n
<
>
o
u
t
p
u
t
[
"
A
d
d
r
e
s
s
e
s
"
]
[
[
1
]
]
;
I
f
[
o
u
t
p
u
t
[
"
S
p
e
n
t
Q
"
]
F
a
l
s
e
,
x
=
t
r
a
n
s
a
c
t
i
o
n
<
>
o
u
t
p
u
t
[
"
S
c
r
i
p
t
S
t
r
i
n
g
"
]
]
;
x
]
I
n
[
]
:
=
Get input hash from an input:
g
e
t
I
n
p
u
t
H
a
s
h
[
i
n
p
u
t
_
]
:
=
B
l
o
c
k
[
{
x
}
,
x
=
i
n
p
u
t
[
"
T
r
a
n
s
a
c
t
i
o
n
I
D
"
]
<
>
i
n
p
u
t
[
"
A
d
d
r
e
s
s
e
s
"
]
[
[
1
]
]
;
x
]
I
n
[
]
:
=
Example:
t
x
=
"
5
4
8
7
e
f
b
9
d
f
a
c
1
6
2
a
d
1
4
5
1
1
d
2
5
d
b
e
f
a
6
6
5
6
e
6
8
7
6
a
f
1
a
7
8
a
1
e
b
0
2
7
b
c
b
4
f
9
f
e
0
b
c
9
"
;
g
e
t
O
u
t
p
u
t
H
a
s
h
[
t
x
,
B
l
o
c
k
c
h
a
i
n
T
r
a
n
s
a
c
t
i
o
n
D
a
t
a
[
t
x
]
[
"
O
u
t
p
u
t
s
"
]
[
[
1
]
]
]
I
n
[
]
:
=
5
4
8
7
e
f
b
9
d
f
a
c
1
6
2
a
d
1
4
5
1
1
d
2
5
d
b
e
f
a
6
6
5
6
e
6
8
7
6
a
f
1
a
7
8
a
1
e
b
0
2
7
b
c
b
4
f
9
f
e
0
b
c
9
1
J
b
G
s
D
H
G
T
9
J
i
P
a
g
e
5
q
d
M
W
J
E
9
5
6
r
j
2
X
f
C
u
b
O
u
t
[
]
=
Graph of a single transaction with outputs
At first, I built a graph with a single transaction and its outputs. Orange vertex represents a transaction, and blue vertices represent its outputs.
Creating the graph:
b
u
i
l
d
T
r
a
n
s
a
c
t
i
o
n
F
o
r
O
n
e
V
e
r
t
e
x
[
t
r
a
n
s
a
c
t
i
o
n
_
]
:
=
B
l
o
c
k
{
i
n
p
u
t
s
,
o
u
t
p
u
t
s
,
n
a
m
e
s
}
,
i
n
p
u
t
s
:
=
B
l
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
u
i
l
d
T
r
a
n
s
a
c
t
i
o
n
F
o
r
O
n
e
V
e
r
t
e
x
[
"
5
4
8
7
e
f
b
9
d
f
a
c
1
6
2
a
d
1
4
5
1
1
d
2
5
d
b
e
f
a
6
6
5
6
e
6
8
7
6
a
f
1
a
7
8
a
1
e
b
0
2
7
b
c
b
4
f
9
f
e
0
b
c
9
"
]
I
n
[
]
:
=
O
u
t
[
]
=
Expanding to multiple transactions
To include multiple vertices into the graph, I start from a pack of transactions and then explore their surrounding using BFS (Breadth-first search) algorithm: when each transaction is processed (further the current processing transaction is mentioned as tx), transactions that were one step before tx (i.e. created its inputs) and transactions that were one step after tx (i.e. where its outputs were spent) are put in the queue, then outputs of tx are added to the graph (just like in the section for one transaction), and the process repeats for next transaction in the queue.
Some transactions may have extraordinary large amount of inputs/outputs, so due to the limited computational power they are cut only to 15 inputs/outputs maximum. However, this way some edges may be lost (e.g. if the 16s output leads to a transaction that is already in a graph, we may lost the edge to it). To deal with this problem I developed a specific function that goes through each input/output and checks whether this input/output is in graph and so the edge should be created.
Finally, total amount of processed transactions is limited too due to the limited computational power.
Building the graph (main function):
b
u
i
l
d
G
r
a
p
h
[
t
r
a
n
s
a
c
t
i
o
n
_
,
v
e
r
t
i
c
e
s
A
m
o
u
n
t
_
,
s
h
o
w
B
i
t
c
o
i
n
s
_
:
T
r
u
e
,
s
h
o
w
N
a
m
e
s
_
:
T
r
u
e
,
v
e
r
t
i
c
e
s
S
i
z
e
_
:
M
e
d
i
u
m
]
:
=
{
C
l
e
a
r
A
l
l
G
l
o
b
a
l
V
a
r
i
a
b
l
e
s
[
]
;
I
n
i
t
i
a
l
i
z
e
V
a
r
i
a
b
l
e
s
[
]
;
q
[
"
P
u
s
h
"
,
{
#
,
0
}
]
&
/
@
t
r
a
n
s
a
c
t
i
o
n
;
(
*
M
a
i
n
W
h
i
l
e
l
o
o
p
f
o
r
B
F
S
a
l
g
o
r
i
t
h
m
*
)
B
l
o
c
k
[
{
c
u
r
T
x
,
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n
s
a
c
t
i
o
n
s
T
o
A
d
d
=
a
d
d
I
n
p
u
t
T
r
a
n
s
a
c
t
i
o
n
s
[
c
u
r
T
x
]
;
I
f
[
L
e
n
g
t
h
[
i
n
p
u
t
T
r
a
n
s
a
c
t
i
o
n
s
T
o
A
d
d
]
>
1
5
,
T
a
k
e
[
i
n
p
u
t
T
r
a
n
s
a
c
t
i
o
n
s
T
o
A
d
d
,
1
5
]
]
;
q
[
"
P
u
s
h
"
,
#
]
&
/
@
i
n
p
u
t
T
r
a
n
s
a
c
t
i
o
n
s
T
o
A
d
d
;
a
d
d
O
u
t
p
u
t
s
A
n
d
P
u
s
h
N
e
x
t
T
r
a
n
s
a
c
t
i
o
n
s
[
]
;
]
]
;
c
o
m
p
l
e
t
e
G
r
a
p
h
[
s
h
o
w
N
a
m
e
s
,
v
e
r
t
i
c
e
s
S
i
z
e
]
;
P
r
i
n
t
[
g
]
;
}
I
n
[
]
:
=
Creating a graph of a random transaction and its surroundings (blue node in the left down corner leads to another transaction, but it isn't depicted on the graph due to the total limit on the processed transactions):
b
u
i
l
d
G
r
a
p
h
[
{
R
a
n
d
o
m
C
h
o
i
c
e
[
B
l
o
c
k
c
h
a
i
n
B
l
o
c
k
D
a
t
a
[
-
4
]
[
"
T
r
a
n
s
a
c
t
i
o
n
L
i
s
t
"
]
]
}
,
3
,
F
a
l
s
e
,
T
r
u
e
]
I
n
[
]
:
=
{
N
u
l
l
}
O
u
t
[
]
=
Examples
E
x
a
m
p
l
e
s
b
e
l
o
w
w
e
r
e
c
r
e
a
t
e
d
b
y
a
p
p
l
y
i
n
g
b
u
i
l
d
G
r
a
p
h
f
u
n
c
t
i
o
n
t
o
r
a
n
d
o
m
t
r
a
n
s
a
c
t
i
o
n
s
i
n
t
h
e
b
l
o
c
k
.
B
a
s
e
d
o
n
t
h
e
s
e
g
r
a
p
h
s
,
a
n
i
n
t
e
r
e
s
t
i
n
g
o
b
s
e
r
v
a
t
i
o
n
c
a
n
b
e
m
a
d
e
-
t
h
e
r
e
a
r
e
s
u
r
p
r
i
s
i
n
g
l
y
m
a
n
y
v
e
r
t
i
c
e
s
(
t
r
a
n
s
a
c
t
i
o
n
s
)
w
i
t
h
a
h
u
g
e
a
m
o
u
n
t
o
f
i
n
p
u
t
s
/
o
u
t
p
u
t
s
.
Graph of a single transaction without labels:
b
u
i
l
d
G
r
a
p
h
[
{
R
a
n
d
o
m
C
h
o
i
c
e
[
B
l
o
c
k
c
h
a
i
n
B
l
o
c
k
D
a
t
a
[
-
4
]
[
"
T
r
a
n
s
a
c
t
i
o
n
L
i
s
t
"
]
]
}
,
5
,
F
a
l
s
e
,
F
a
l
s
e
]
I
n
[
]
:
=
{
N
u
l
l
}
O
u
t
[
]
=
Graph of surrounding of two random transactions from one block. Since the graph has two components, these transactions are not connected in this part of the blockchain (probably they are connected in another part that is not depicted in the graph):
b
u
i
l
d
G
r
a
p
h
[
{
R
a
n
d
o
m
C
h
o
i
c
e
[
B
l
o
c
k
c
h
a
i
n
B
l
o
c
k
D
a
t
a
[
-
4
]
[
"
T
r
a
n
s
a
c
t
i
o
n
L
i
s
t
"
]
]
,
R
a
n
d
o
m
C
h
o
i
c
e
[
B
l
o
c
k
c
h
a
i
n
B
l
o
c
k
D
a
t
a
[
-
4
]
[
"
T
r
a
n
s
a
c
t
i
o
n
L
i
s
t
"
]
]
}
,
6
,
F
a
l
s
e
,
F
a
l
s
e
]
I
n
[
]
:
=
{
N
u
l
l
}
O
u
t
[
]
=
Graph of three transactions with labels and Bitcoin amount:
b
u
i
l
d
G
r
a
p
h
[
{
R
a
n
d
o
m
C
h
o
i
c
e
[
B
l
o
c
k
c
h
a
i
n
B
l
o
c
k
D
a
t
a
[
-
4
]
[
"
T
r
a
n
s
a
c
t
i
o
n
L
i
s
t
"
]
]
}
,
3
,
T
r
u
e
,
T
r
u
e
,
S
m
a
l
l
]
I
n
[
]
:
=
{
N
u
l
l
}
O
u
t
[
]
=
Graph with 10 transactions without labeling vertices and depicting Bitcoin amount:
b
u
i
l
d
G
r
a
p
h
[
{
R
a
n
d
o
m
C
h
o
i
c
e
[
B
l
o
c
k
c
h
a
i
n
B
l
o
c
k
D
a
t
a
[
-
4
]
[
"
T
r
a
n
s
a
c
t
i
o
n
L
i
s
t
"
]
]
}
,
1
0
,
F
a
l
s
e
,
F
a
l
s
e
,
L
a
r
g
e
]
I
n
[
]
:
=
{
N
u
l
l
}
O
u
t
[
]
=
Graph with 20 transactions without labeling vertices and depicting Bitcoin amount (last parameter means the size of vertices):
b
u
i
l
d
G
r
a
p
h
{
R
a
n
d
o
m
C
h
o
i
c
e
[
B
l
o
c
k
c
h
a
i
n
B
l
o
c
k
D
a
t
a
[
-
4
]
[
"
T
r
a
n
s
a
c
t
i
o
n
L
i
s
t
"
]
]
}
,
2
0
,
F
a
l
s
e
,
F
a
l
s
e
,
{
"
S
c
a
l
e
d
"
,
.
0
1
}
{
{
{
N
u
l
l
}
}
,
{
}
}
O
u
t
[
]
=
Graph with 40 transactions without labeling vertices and depicting Bitcoin amount (last parameter means size of vertices):
b
u
i
l
d
G
r
a
p
h
[
{
R
a
n
d
o
m
C
h
o
i
c
e
[
B
l
o
c
k
c
h
a
i
n
B
l
o
c
k
D
a
t
a
[
-
4
]
[
"
T
r
a
n
s
a
c
t
i
o
n
L
i
s
t
"
]
]
}
,
4
0
,
F
a
l
s
e
,
F
a
l
s
e
,
{
"
S
c
a
l
e
d
"
,
.
0
0
5
}
]
I
n
[
]
:
=
{
N
u
l
l
}
O
u
t
[
]
=
A
p
p
e
n
d
i
x
Future Work
Wolfram Resource Function Multiway Function System may be useful in building even more detailed graphs that are easy to analyze. However, it may be difficult to implement it for Bitcoin Transaction because of the specific nature of Bitcoin transaction data, but I think exploring this direction may be interesting.
There are numerous opportunities in Bitcoin graph visualization that may be used to make transaction graphs easier to understand and more informational. For example, sizes of vertices or color brightness may be used to show the amount of Bitcoins in each output.
Keywords
Bitcoin
◼
Graph theory
◼
Cryptocurrency
◼
Blockchain
◼
POSTED BY:
Egor Bugaev
Answer
Mark as an Answer
Reply
|
Flag
Reply to this discussion
in reply to
Add Notebook
Community posts can be styled and formatted using the
Markdown syntax
.
Tag limit exceeded
Note: Only the first five people you tag will receive an email notification; the other tagged names will appear as links to their profiles.
Publish anyway
Cancel
Reply Preview
Attachments
Remove
Add a file to this post
Follow this discussion
or
Discard
Group Abstract
Be respectful. Review our
Community Guidelines
to understand your role and responsibilities.
Community Terms of Use
Feedback
Enable JavaScript to interact with content and submit forms on Wolfram websites.
Learn how »