Proof of Existence Part 2 — Creating data stream to store hash of the file and metadata in blockchain network.
Step 1: First we would create a new blockchain named chain1
. On the first server, run this command:
multichain-util create chain1
Step 2 : Initialize the blockchain, including mining the genesis block. multichaind chain1 -daemon
Step 3 : Get info of blockchain run command (multichain-cli chain1).
sourabhsethi8888@mutichain-instance-1:~$ multichain-cli chain1
MultiChain Core RPC client build 1.0 alpha 26 protocol 10006
Interactive mode
chain1: getinfo
{"method":"getinfo","params":[],"id":1,"chain_name":"chain1"}
{
"version" : "1.0 alpha 26",
"protocolversion" : 10006,
"chainname" : "chain1",
"description" : "MultiChain chain1",
"protocol" : "multichain",
"port" : 9565,
"setupblocks" : 60,
"nodeaddress" : "chain1@10.142.0.4:9565",
"burnaddress" : "1XXXXXXWZzXXXXXXYBXXXXXXbVXXXXXXWsKJr3",
"incomingpaused" : false,
"miningpaused" : false,
"walletversion" : 60000,
"balance" : 0.00000000,
"walletdbversion" : 2,
"reindex" : false,
"blocks" : 15549,
"timeoffset" : 0,
"connections" : 0,
"proxy" : "",
"difficulty" : 0.00001526,
"testnet" : false,
"keypoololdest" : 1530472920,
"keypoolsize" : 2,
"paytxfee" : 0.00000000,
"relayfee" : 0.00000000,
"errors" : ""
}
chain1:
Step 4: Create stream POE in chain1.
Now let’s create a stream POE, which can be used for general data storage and retrieval.
chain1: create stream poe false
{"method":"create","params":["stream","poe",false],"id":1,"chain_name":"chain1"}
922ce92090a540222ccd2cb9349d7fc34fd83570938b9e500102543189667f95
chain1:
The false
means the stream can only be written to by those with explicit permissions. Let’s see its permissions:
chain1: listpermissions poe.*
{"method":"listpermissions","params":["poe.*"],"id":1,"chain_name":"chain1"}
[
{
"address" : "1HGMosmcKEPUnwD2DzNUfQ46HCA9Th4mBZCZEF",
"for" : {
"type" : "stream",
"name" : "poe",
"streamref" : "15591-267-11410"
},
"type" : "admin",
"startblock" : 0,
"endblock" : 4294967295
},
{
"address" : "1HGMosmcKEPUnwD2DzNUfQ46HCA9Th4mBZCZEF",
"for" : {
"type" : "stream",
"name" : "poe",
"streamref" : "15591-267-11410"
},
"type" : "activate",
"startblock" : 0,
"endblock" : 4294967295
},
{
"address" : "1HGMosmcKEPUnwD2DzNUfQ46HCA9Th4mBZCZEF",
"for" : {
"type" : "stream",
"name" : "poe",
"streamref" : "15591-267-11410"
},
"type" : "write",
"startblock" : 0,
"endblock" : 4294967295
}
]
chain1:
subscribe poe
chain1: subscribe poe
{"method":"subscribe","params":["poe"],"id":1,"chain_name":"chain1"}
Step 5: So for now, only the first server has the ability to write to the stream, as well as administrate it. Let’s publish something to it, with key key1
:
chain1: publish poe key1 73747265616d2064617461
{"method":"publish","params":["poe","key1","73747265616d2064617461"],"id":1,"chain_name":"chain1"}
744f9a635f6fb34ee9fa58245341d6d9799574c94fa2c5dc960e7961b80d9f81
chain1:
Step 6: Now let’s query the stream’s contents in many different ways.
liststreamitems
poe
chain1: liststreamitems poe
{"method":"liststreamitems","params":["poe"],"id":1,"chain_name":"chain1"}
[
{
"publishers" : [
"1HGMosmcKEPUnwD2DzNUfQ46HCA9Th4mBZCZEF"
],
"key" : "key1",
"data" : "922ce92090a540222ccd2cb9349d7fc34fd83570938b9e500102543189667f95",
"confirmations" : 22,
"blocktime" : 1530693688,
"txid" : "525cc31b4de0627f19a9bea627fad933252d8ccecdf7a7a04cbf9a3486686f78"
},
{
"publishers" : [
"1HGMosmcKEPUnwD2DzNUfQ46HCA9Th4mBZCZEF"
],
"key" : "key1",
"data" : "73747265616d2064617461",
"confirmations" : 6,
"blocktime" : 1530693893,
"txid" : "744f9a635f6fb34ee9fa58245341d6d9799574c94fa2c5dc960e7961b80d9f81"
}
]
chain1:chain1: liststreamkeys poe
{"method":"liststreamkeys","params":["poe"],"id":1,"chain_name":"chain1"}
[
{
"key" : "key1",
"items" : 2,
"confirmed" : 2
}
]chain1: liststreampublishers poe
{"method":"liststreampublishers","params":["poe"],"id":1,"chain_name":"chain1"}
[
{
"publisher" : "1HGMosmcKEPUnwD2DzNUfQ46HCA9Th4mBZCZEF",
"items" : 2,
"confirmed" : 2
}
]
chain1:
Conclusion : One would be able to understand the Streams in multichain network to store the data in blockchain.