Getting Commenced with MultiChain, MultiChain
Getting Commenced with MultiChain
Create and deploy your very first private blockchain in minutes
This tutorial requires two server knots. If you have not done so already, please download and install MultiChain on each server. If you are using MultiChain on Windows, please read the Windows notes in the README.txt file to adapt the instructions below.
1. Creating a blockchain
Very first we will create a fresh blockchain named chain1 . On the very first server, run this instruction:
multichain-util create chain1
(If you are using Windows, you need to very first open a DOS instruction line in the directory where you installed the MultiChain executables. You can do this by navigating to that directory in the Windows Explorer, then typing cmd in the address bar at the top.)
View the blockchain’s default settings (these can also be modified but we recommend using the defaults for now):
/.multichain/chain1/params.dat (on Windows, view %APPDATA%\MultiChain\chain1\params.dat )
Initialize the blockchain, including mining the genesis block:
multichaind chain1 -daemon
You should be told that the server has began and then after a few seconds, that the genesis block was found. You should also be given the knot address that others can use to connect to this chain.
Copy and paste the knot address here:
Two. Connecting to a blockchain
Now we’ll connect to this blockchain from elsewhere. On the 2nd server, run the following:
You should be told that the blockchain was successfully initialized, but you do not have permission to connect. You should also be shown a message containing an address in this knot’s wallet.
Copy and paste the wallet address here:
Back on the very first server, add connection permissions for this address:
multichain-cli chain1 grant connect
Now attempt reconnecting again from the 2nd server:
multichaind chain1 -daemon
You should be shown a message that the knot was began, and it should display this 2nd knot’s address.
Three. Some guidelines in interactive mode
Before we proceed, let’s inject interactive mode so we can issue directions without typing multichain-cli chain1 every time. On both servers:
(If you are using Windows, interactive mode is not yet available, so all directions in this guide should be preceded by multichain-cli chain1 . You will also need to open another DOS directive line in the directory where you installed the MultiChain executables.)
Now that the blockchain is working on two knots, you can run the instructions in this section on either or both. To get general information:
See a list of all available directions:
Display all permissions presently assigned:
Create a fresh address in the wallet:
List all addresses in the wallet:
Get the parameters of this blockchain (based on params.dat file):
For each knot, get a list of connected peers:
Four. Using native assets
If you only interested in blockchains for data storage and retrieval, rather than signifying asset transactions, skip straight to section 6.
Now we are going to create a fresh asset and send it inbetween knots. On the very first server, get the address that has the permission to create assets:
Copy and paste the displayed address here:
Now we’ll create a fresh asset on this knot with one thousand units, each of which can be subdivided into one hundred parts, sending it to itself:
issue asset1 one thousand 0.01
On both servers, verify that the asset named asset1 is listed:
Now check the asset balances on each server. The very first should demonstrate a balance of one thousand , and the 2nd should display no assets at all:
On the very first server, now attempt sending one hundred units of the asset to the 2nd server’s wallet:
sendasset asset1 100
You should see an error that the address does not have receive permissions. So it’s time to add receive and send permissions:
Now attempt sending the asset again, and it should go through:
sendasset asset1 100
Now check the asset balances on each server, including transactions with zero confirmations. They should be nine hundred and one hundred respectively:
You can also view the transaction on each knot and see how it affected their balances:
Five. Transaction metadata
In this section we’ll create a transaction that sends one hundred twenty five units of asset1 along with some metadata. On the very first server, run:
Copy and paste the displayed transaction ID:
Now this transaction can be examined on the 2nd server as below:
In the output from this instruction, you should see the balance field demonstrating the incoming one hundred twenty five units of asset1 and the data field containing the hexadecimal metadata that was added.
Now let’s create a stream, which can be used for general data storage and retrieval. On the very first server:
create stream stream1 false
The false means the stream can only be written to by those with explicit permissions. Let’s see its permissions:
So for now, only the very first server has the capability to write to the stream, as well as administrate it. Let’s publish something to it, with key key1 :
publish stream1 key1 73747265616d2064617461
The txid of the stream item is returned. Now let’s see that the stream is visible on another knot. On the 2nd server:
(The root stream was in the blockchain by default.) Now we want the 2nd server to subscribe to the stream, then view its contents:
Now we want the 2nd server to be permitted to publish to the stream. On the very first server:
Note that the address needs both general send/receive permissions for the blockchain, as well as permission to write to this specific stream. Now let’s publish a duo of items on the 2nd server:
publish stream1 key1 736f6d65206f746865722064617461
publish stream1 key2 53747265616d732052756c6521
Now let’s query the stream’s contents in many different ways. Back on the very first server:
liststreamitems stream1 (should demonstrate three items)
liststreamkeys stream1 (Two keys)
liststreamkeyitems stream1 key1 (Two items with this key)
liststreampublishers stream1 (Two publishers)
liststreampublisheritems stream1 (Two items by this publisher)
This is just a taste of the ways in which flows can be queried – for more information, please consult the API documentation.
7. Round-robin mining
In this section we’ll embark collaborative mining inbetween the knots. On the very first server, run:
On the 2nd server, check that two permitted miners are listed:
If you are using MultiChain 1.0 alpha twenty eight or later, run this on both servers to maximize the degree of miner randomness:
setruntimeparam miningturnover 1
Now wait for a duo of minutes, so that a few blocks are mined. (This assumes you left the block time on the default of fifteen seconds.) On either server, check the current block height:
The block height is in the blocks field of the response. Now let’s get information about the last few blocks, beginning with this one:
The address of the miner of each block is in the miner field of the response. In different blocks you should see the two different addresses in this field.
8. Now go explore…
Congratulations – you have finished the very first tutorial! Now you attempt any of the other tutorials, create blockchains with different parameters or explore the available API directions. You can also install the Explorer or Web Demo to see a graphical interface for your blockchain.
Ultimately, you may want to subscribe below for updates. And if you have any questions or problems, please ask in the developer Q&A or contact us.