Current location - Training Enrollment Network - Books and materials - Hot! Create and play your own blockchain in 5 minutes.
Hot! Create and play your own blockchain in 5 minutes.
This year's blockchain development is really fast! From an unfamiliar concept at the beginning, all industries have started now, and a single spark has the potential to start a prairie fire. I really hope to have my own blockchain coach! However, how can a person and a computer build a blockchain where the blockchain environment is too hot? It's not easy to say I love you!

Don't worry! Bian Xiao has been fascinated by blockchain and smart contracts! Now I will take you from scratch and play my own blockchain in 5 minutes! ~

The super cloud platform developed by IBM China Research Institute provides a blockchain development and testing environment for blockchain enthusiasts and developers. Through this platform, users can create multi-node blockchain based on Hyperledger Fabric for free and super quickly, and play smart contracts in their own chains.

-

0.

Preparatory work/about to start work

Just need your local browser!

1. Registered account

The public test address for accessing the super ship blockchain service is 8800/bc.

Click the login button in the upper right corner, click Register in the pop-up window, fill in the email address and password, and submit. At this time, it is recommended to check the activation email in the mailbox and activate your account (Bian Xiao tip: it doesn't matter if you are lazy to activate, but some advanced services must be activated before you can use them).

2.

Quickly create your own blockchain.

After the registration is completed, go back to the home page and click on the huge give me a blockchain (give me a blockchain! ) button. Select the consensus plug-in (* * * plug-in) and size (number of blockchain network nodes) you want in the pop-up box.

Note: At present, you can choose two * * * plug-ins officially provided by Hyperledger Fabric: noops and pbft.

After clicking Submit, you can get your own blockchain in a few seconds and automatically enter the monitoring panel. Yes, getting your own blockchain is as simple as that!

After entering the monitoring panel, you can see the smart contract management panel on the left, including the management and deployment of smart contracts; On the right is the network panel, which shows the applied blockchain network, and the topology and delay information between nodes are clear at a glance; Click the telescope icon in the upper right corner to monitor the log information of each node in real time. At the bottom is the blockchain panel, which shows the overall situation of the current blockchain. In the initial state, there is only one block.

3. Deploying and using smart contracts

Next, Bian Xiao teaches you how to deploy and use smart contracts on your own blockchain.

Under the smart contract tab of the smart contract management panel, two smart contracts are listed as examples, namely map and chaincode_example02. Map contract can store key-value pairs, and chaincode_example02 contract can simulate the transfer and query of two people.

Note: The codes of these two sample contracts can be found in the source code of Hyperledger Fabric.

Take the deployment and use of chaincode_example02 contract as an example:

Deployment contract

Click the deployment button corresponding to the chaincode_example02 contract, and fill in the initial values of the contract, including the contract name, initial function and initial parameters. The initial function of the contract is init, and the initial parameters need to be filled in according to the format, such as ["a", "100", "b" and "200"], which means that two people A and B are registered and given to 100 and 200 units respectively.

Click the deploy button, and the contract will be deployed to your blockchain, which takes about 20~40 seconds. When a new block appears in the blockchain panel, it usually means that the contract has been deployed.

Buy contract

After deployment, view the deployed contract instances under the My Deployment tab of the smart contract management panel.

Click the Invoke button below the action to call the smart contract, and fill in the called method name and corresponding parameters (the method names and parameters of different contracts have different meanings, which are related to the contract content). For this contract, call the invoke method name and fill in the parameters ["A", "B" and "50"], which means that A transfers 50 units to B. ..

After clicking Submit to complete the call, you can view the blockchain situation, and a new block will be generated at this time.

Inquiry contract

After the call is completed, you can query the contract execution results. Still under the My Deployment tab, click the Query button under Operations to query the smart contract, and fill in the query method name and corresponding parameters. If the query method name is selected, fill in the parameter ["A"], which indicates the current company of query A. ..

After clicking Submit, you can see that the current unit of A is 50. You can try querying B again!

Ok, then you can continue to operate the contract, observe the blockchain, or deploy a new smart contract in the blockchain, such as a map. For convenience, the method name and parameter format of deployment, call and query contracts are filled in by default. You just need to choose a method name and change the parameters according to the description of the cat! See how long you can play the chain ~

4. Upload and test your own private smart contract.

In addition to the two public smart contracts currently available, you can also upload and test your own private contracts! Private contracts can only be read by themselves.

Click Import Private Smart Contracts under the Smart Contracts tab.

Fill in the contract name and description, upload the contract coding file, and click Import to finish uploading.

After that, the contract I uploaded will appear in the smart contract list, which can be deployed, called and queried as before.