File Exchange

image thumbnail

MATLAB Blockchain Example

version 2.0.0.0 (195 KB) by Roger Aarenstrup
A MATLAB app that implements a distributed blockchain.

29 Downloads

Updated 16 Apr 2018

View Version History

View License

This example shows a blockchain implementation in MATLAB. Several nodes can be run to distribute the blockchain and blocks can be mined or blocks with invalid hashes can be added for test. Although the current implementation requires parallel computing toolbox it can easily be changed to run without it.
Note that the app is made for 2018a pre-release.

Cite As

Roger Aarenstrup (2020). MATLAB Blockchain Example (https://www.mathworks.com/matlabcentral/fileexchange/65419-matlab-blockchain-example), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (34)

othman alnajar

Amirah Almutairi

Hi all , when I tried to run the application ,it shows me the below error:
I don't know what should be the first step , I tried to create workarea but I couldn't
>> runapp
Error using cd
Cannot CD to /Users/ameera/Desktop/Blockchain2/MATLAB_Blockchain_v2/Workarea (Name is nonexistent or not a directory).

Error in runapp (line 5)
cd Workarea

Abdulaziz Alzahrani

Hi, When I press add client show me this message and I don't know where is the error?

### Inside Add Client
*** ERROR closing client
Undefined function 'udp' for input arguments of type 'char'.

Error in p2p.ClientNode (line 17)
obj.udp_obj = udp(addr, ...

Error in p2p.ClientNodeSet/add_client (line 21)
tmp_node = p2p.ClientNode(addr, remote_port, local_port);

Error in MATLAB_Blockchain/StartButtonPushed (line 75)
node = app.nodes.add_client(app.AddressEditField.Value,
app.RemotePortEditField.Value, app.LocalPortEditField.Value);

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.

Annabelle Nwaokorie

Why do I receive this error when i edit the data edit box to "00hello"? I cannot see the blockchain reciprocated in the other Matlab instance.

Undefined function 'parfeval' for
input arguments of type
'function_handle'.

Error in
MATLAB_Blockchain/MineBlockButtonPushed
(line 200)
parfeval(@bc.mine2,
0, app.q, index,
prev_hash,
timestamp,
app.DataEditField.Value);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.

.xUndefined function 'poll' for
input arguments of type
'double'.

Error in
MATLAB_Blockchain/StartButtonPushed
(line 57)
[block,
gotMsg] =
poll(app.q,
1);

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.

jeyasheela rakkini

how to add some 100 clients in this program

Junwei Liang

I did all the procedures as the sbs.txt, but I can't see any new block added. How do I fix this? And when I click add block there is an error "Undefined variable "System" or class
"System.Security.Cryptography.SHA256Managed""

GOPAL RAWAT

No public property ZTick exists for class matlab.ui.control.UIAxes.

Error in MATLAB_Blockchain/createComponents (line 262)
app.UIAxes.ZTick = [];
hi getting error :

Error in MATLAB_Blockchain (line 338)
createComponents(app)

Error in runapp (line 7)
MATLAB_Blockchain

nesma gomaa

hi when i'm running the program, i found this error

No public property ZTick exists for class matlab.ui.control.UIAxes.

Error in MATLAB_Blockchain/createComponents (line 262)
app.UIAxes.ZTick = [];

Error in MATLAB_Blockchain (line 338)
createComponents(app)

Error in runapp (line 7)
MATLAB_Blockchain

Error setting property 'Enable' of class 'Button':
Value must be specified as the character vector 'on' or 'off'

Error in MATLAB_Blockchain/StartButtonPushed (line 49)
app.StopButton.Enable = true;

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 310)
Error while evaluating Button PrivateButtonPushedFcn.

can anyone help?

BINGYANG HU

In the mine.m file, why did it need pause 0.0003 in each loop?

moses acquah

the step file mentions the hash after being mined to contain first 0000's but with the random characters there's no way to see that.

Raahul Vignesh

As per the instructions in the step by step file, I pressed add client but i'm not getting any error as mentioned in the file. What should I do ?

moses acquah

Roger Aarenstrup

The characters represent the numbers of the hash. >> char(val) where val can have any base.

moses acquah

he hash value appears as scrambled characters,, it should be appears in hex.. any idea ?

Roger Aarenstrup

Create a folder called Workarea first.

C Ananth

in step 1, i tried to run the runapp but it gaves me that error. What should i do?
Error using cd
Cannot CD to Workarea (Name is nonexistent or not a directory).
Error in runapp (line 5)
cd Workarea

Saif Al Janabi

the hash value appears as scrambled characters,, it should be appears in hex.. any idea ?

thomas kim

Like Luis Cardoso, I had same issue. It seems like matlab can't interpret Workarea

Hamza Anwar

Can anyone explain how to add multiple (more than 2) nodes and connect them. For connecting two nodes the procedure is given in the step-by-step file which is to set the correct remote and local port values [Node1's Remote Port = Node2's Local Port, and vice versa]. but how to do this for more than two clients/nodes is unclear. Thank you

Luis Cardoso

in step 1, i tried to run the runapp but it gaves me that error. What should i do?
Error using cd
Cannot CD to Workarea (Name is nonexistent or not a directory).
Error in runapp (line 5)
cd Workarea

Roger Aarenstrup

Hi Matt, you need to start two MATLAB instances and run the app in each. So there is only one app but it is run in two MATLAB instances.

Matt

In the instruction, there show "two app", I just found one. how to run? Thanks.

Roger Aarenstrup

In the doc folder you have a file: sbs.txt (step-by-step)

Hagos Welejewergs

well done, but can you provide us steps to run the program. Thanks.

Roger Aarenstrup

Yes, the code use TCIP/IP calls from instrument control toolbox.

Sean HY Yuan

Hi, do we have to install instrument control toolbox? why would you need it?

Roger Aarenstrup

Did you change the ports to match? Did you read the instructions?

jalashree trivedi

i tried running multiple instances of this app on the same machine and tried adding clients..is it possible? doesnt seem to work..may be im missing something here...

Roger Aarenstrup

You need to start more matlab instances and from each a client. You could probably also use matlab compiler to deploy clients.

jalashree trivedi

great work..but how to add clients..just not able to make that work..

Xiaolong zheng

Hans Scharler

jalashree trivedi

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!