How to be a blockchain developer (1)

High availability architecture 2021-04-01 21:56:49 阅读数:715

本文一共[544]字,预计阅读时长:1分钟~
blockchain developer

Reading guide : As blockchain becomes a national strategy , The central bank also launched digital currency , The industry has a growing demand for employees in the blockchain industry ; In addition, the price of bitcoin has hit a new high recently , Decentralized Finance DeFi Applications are also very hot , Amateur programmers also need to develop and understand blockchain . High availability architecture translation blockgeeks A series of articles , Help you better learn and understand blockchain development .


In this paper , We'll show you how to be a blockchain Development Engineer . As you will see soon , Blockchain development is not fundamentally different from ordinary Internet development . In order to make it easy for everyone to get started , We have written this guide to help you learn about blockchain development , And the summary operation steps are given in each section .


In the early days, the development scope of bitcoin was relatively limited , However, with the release of Ethereum , The rules of the game for blockchain development have fundamentally changed , Ethereum is the world's first programmable blockchain . Developers around the world finally have the opportunity to build their own applications on the blockchain . This is one of the reasons why learning blockchain development has become such a popular skill .


Beyond all doubt , We are already living in “ Blockchain era ”, It has a huge impact on our future . that , How can we get a piece of this blockchain revolution ? If you want to be a blockchain Developer , Then you need to follow a certain method .


Hopefully through this guide , You can start your blockchain journey . If you want to be a real blockchain Developer , We need to set some expectations for you . First , It takes time , Invest your time and resources in learning . secondly , Don't expect immediate results , Blockchain development cannot be achieved overnight .


Said so much , Let's get down to business .


Become a blockchain Developer — Milepost #1: Know the basics


Blockchain development tools


For any new revolutionary technology , For example, blockchain , One of the biggest obstacles is getting familiar with the concepts that are indispensable to the system .


If you're a blockchain beginner , You need to be familiar with certain terms .


Learning blockchain Technology


  1. Blockchain : Blockchain (1) It's a chain of blocks , Each block stores the corresponding data , It doesn't have any centralized regulation , It's security and data immutability through cryptography .

  2. De centralization : Blockchains are considered decentralized , Because there is no centralized agency to supervise .

  3. Consensus mechanism : A mechanism for decentralized networks to reach consensus on certain issues (2).

  4. The miners : Using computing power to mine new users .


I suggest you learn more about these terms that are widely used in the field of encryption . You can also browse our comprehensive vocabulary (3). It's important to understand these basic terms , Otherwise, you will be very confused in further study .


If you're interested in how to create a fintech application on top of the blockchain , Then you must learn the background of encryption economics . Most developers are usually proficient in “ encryption ” part , But it could be right “ economics ” Know nothing about the part of knowledge .


In view of this , Read about economics , Have a general understanding of it . If you want to understand the economics of encryption in general , So you can check out our article here (4).


If you're particularly interested in cryptography , Want to know how digital signatures work , And understand the meaning of public key cryptography , So read this (5).


after , It's highly recommended that you understand how bitcoin works , Bitcoin is the most widely spread blockchain technology 、 best 、 One of the most elegant applications . You can even say that it's the best example that blockchain technology can achieve , Based on its impact . So I suggest you read Nakamoto's bitcoin white paper (6)


(1) https://blockgeeks.com/guides/what-is-blockchain-technology/

(2) https://blockgeeks.com/guides/what-is-cryptoeconomics/

(3) https://blockgeeks.com/guides/blockchain-glossary-from-a-z/

(4) https://blockgeeks.com/guides/what-is-cryptoeconomics/

(5) https://blockgeeks.com/guides/cryptocurrencies-cryptography/

(6) https://bitcoin.org/bitcoin.pdf


Now? , This completes the first milestone .


Let's review the action plan you need to complete in this step .


  • Familiar with various technical terms .

  • Read more about blockchain Technology .

  • Read the bitcoin white paper .


Become a blockchain Developer  —  Milepost #2: Familiar with the process


See a lot of new entrants " developer " No first-hand experience of the real world , It's amazing . If you don't use a system once , How can it be innovated and improved ?


Therefore, it is strongly recommended that you become familiar with this system from today on .


Go to Coinbase Or any other exchange you're familiar with to buy some coins . You don't need to create a broad portfolio , Just buy some coins to see how the whole process works .


It's very direct . Since you're not going to buy a lot of money , So just use a basic online wallet .


These wallets are the easiest to use of all wallets . Creating super simple , Because it basically creates its own account on any exchange service . Besides , You can access this wallet from any server or device in the world , As long as it's connected to the network . Speaking of this , There's a big problem with online wallets . Your private key will be saved on another server . It's basically like giving your key to a hacker on a silver basin . Don't use online wallets to store large amounts of money . Only deposit the minimum amount you need to test the transaction purpose .


When you create a broad cryptocurrency Portfolio , You have to learn how to use a cold wallet to store your money . You can learn how to do it here . later , If you start your fundraising , Then you have to know the wallet , In particular, how multi signature wallets work .


This part will also end , The hard part starts with the next milestone .


The action plan in this section includes :


  • Understand how exchanges work

  • Know how to use your wallet .


Become a blockchain Developer  —  Milepost 3: Start coding


As a blockchain Developer , We're going to face a lot of challenges at the back end . For some reason , It's not easy to create and maintain a public chain .


reason 1: Security


just as David Schwartz said , Blockchain should be a fortress . First , The code is public , Everyone can see . Anyone can look at the code , Check for bugs and vulnerabilities . However , Unlike other open source code , The disadvantage of looking for vulnerabilities in blockchain code is huge . Any programmer can hack , And it's possible to get millions of dollars or even millions of dollars . Because of these reasonable safety considerations , Development on the blockchain is usually very slow .


Reason two : Resource management


It's important to keep up with the pace of the Internet , We can't lag behind and keep up with all the network requests . You need to deal with access to remote and local queries .


reason 3: performance


Blockchain must always execute with the highest possible capability , But to do that , The language chosen must be very generic . The problem is , Some tasks in the blockchain can be parallel , And some tasks can't be done in parallel .


Digital signature verification is a good example of parallelizable tasks . All you need for signature verification is a key 、 Transactions and signatures . Just three data , You can verify it in parallel .


However , Not all functions on the blockchain should do this . Think about the execution of the deal itself . Multiple transactions cannot be executed in parallel , You need to do one at a time , In order to avoid logic mistakes such as double spending . Some languages are good at parallel operation , And some languages are good at nonparallel operations .


reason 4: Isolation


What is deterministic behavior ?


If A+B=C, So in any case ,A+B Always equal to C, It's called deterministic behavior .


Hash functions are deterministic , namely A The hash value of is always H(A).


therefore , In blockchain development , All trading operations must be deterministic . You can't have a trading behavior that is a way , And then the next day it was another way . Again , You can't have smart contracts work in two different ways on two different machines .


The only solution is isolation . Basically , You isolate your smart contracts and transactions from the elements of uncertainty .


There are some languages that can meet most of the needs , If you're a blockchain Developer , So you definitely need to master some C++ and JavaScript Basic knowledge of .


although C++ It may look a little out of date , But the truth is , It wonderfully fulfills all the functions we described above . in fact , Nakamoto uses C++ Wrote the bitcoin source code .


It is associated with HTML and CSS Together , yes WWW One of the three core technologies of content production .Javascript Usually used to create user interactive web pages .


that , Now let's see how to use Javascript Create a very simple blockchain .


How do we create a block ? What does a simple block consist of ? In the simple cryptocurrency we're going to develop ( Let's call it alpha "BlockGeeksCoin"), Each block contains the following information :


  • Indexes : Block number

  • Time stamp : When the block was created

  • data : Data in blocks

  • Previous Hash: Of the last block hash value .

  • Hash value : Current block Hash value .


Before we move on , You need to understand some of the terms we use in the program .


  • This: "this " Keywords are called in functions , It allows you to access the value of the specific object that calls the function .

  • Constructors . The constructor is a special function , It can help create and initialize an object in a class . Each class can only have one constructor .


It's almost there , Let's start creating our blocks .


Create new block code


const SHA256 = require("crypto-js/sha256"); 
class Block
{
constructor(index, timestamp, data, previousHash = '')
{
this.index = index;
this.previousHash = previousHash;
this.timestamp = timestamp;
this.data = data;
this.hash = this.calculateHash();
}
calculateHash()
{
return SHA256(this.index + this.previousHash + this.timestamp + JSON.stringify(this.data)).toString();
}
}


The code analysis


Okay , Here's a block created . In the first line of the code , We call crypto-js library , because sha256 Hash function in JavaScript It is not provided by default in .


Next , We call a constructor in the class , To call an object with a certain value . What catches your eye may be calculateHash() function . Let's see what it's doing .


In a block , We hash everything , Get the hash value of the specific block . We use JSON.stringify Function to hash the block data into a string .


Okay , We're ready for a piece of , We can start . Now let's connect these blocks into a blockchain .


class Blockchain
{
//Section 1 Genesis block creation
constructor()
{
this.chain = [this.createGenesisBlock()];
}
createGenesisBlock()
{
return new Block(0, "01/01/2017", "Genesis block", "0");
}
//section 2 adding new blocks
getLatestBlock()
{
return this.chain[this.chain.length - 1];
}
addBlock(newBlock) {
newBlock.previousHash = this.getLatestBlock().hash;
newBlock.hash = newBlock.calculateHash();
this.chain.push(newBlock);
}
//section 3 validating the chain
isChainValid()
{
for (let i = 1; i < this.chain.length; i++)
{
const currentBlock = this.chain[i];
const previousBlock = this.chain[i - 1];
if (currentBlock.hash !== currentBlock.calculateHash()) {
return false;
}
if (currentBlock.previousHash !== previousBlock.hash)
{
return false;
}
}
return true;
}
}


The code analysis


Okay , A lot of things are done in the code above , We divide it into several parts .


The first part : Genesis block


What is Genesis block ?


The genesis block is the first block in the blockchain , It's special , Because each block points to the previous block , And the genesis block doesn't point to anything . therefore , The moment you create a new chain , The genesis block will be created immediately .


therefore , You can see a createGenesisBlock() function , In this function , We give the block data manually .


createGenesisBlock() 
{ return new Block(0, "01/01/2017", "Genesis block", "0"); }


The second part : Add Block


First , We need to know what the latest block in the current blockchain is . So , We use getLatestBlock() function .


getLatestBlock() 
{
return this.chain[this.chain.length - 1];
}
Now that we have determined the latest block, let’s see how we are going to add new blocks.
addBlock(newBlock) {
newBlock.previousHash = this.getLatestBlock().hash;
newBlock.hash = newBlock.calculateHash();
this.chain.push(newBlock);
}


that , What happened here ? How we add blocks ? How do we check whether a given block is valid ?


Remember the contents of a block ? Each block has the hash value of the previous block , Am I right? ?


therefore , What we're going to do here is simple . Put the new block of previousHash Compare with the last block hash .


If the two values match , That means the new block is legal , It's added to the blockchain .


The third part : Verification chain


Now? , We need to check that no one is breaking our blockchain , Everything is stable .


We use for Loop from block 1 To the last block . The genesis block is a block 0.


for (let i = 1; i < this.chain.length; i++)
{
const currentBlock = this.chain[i];
const previousBlock = this.chain[i - 1];

In this part of the code we are defining two terms, current block and previous block. And now we are simply going to find the hash of these two values.
if (currentBlock.hash !== currentBlock.calculateHash()) {
return false;
}
if (currentBlock.previousHash !== previousBlock.hash)
{
return false;
}
}
return true;
}


If the current block previousHash Not equal to the previous block Hash, So this function will return False, Otherwise it will return True.


Use blockchain


Now? , We're finally going to use blockchain to create our BlockGeeksCoin 了 .


let BlockGeeksCoin = new Blockchain(); 
BlockGeeksCoin.addBlock(new Block(1, "20/07/2017", { amount: 4 }));
BlockGeeksCoin.addBlock(new Block(2, "20/07/2017", { amount: 8 }));


this is it !


So what's going on here ?


We created a new cryptocurrency based on blockchain , And named it BlockGeeksCoin. By calling this new object , I activated the constructor , And then automatically created the genesis block .


We just need to add two more blocks to it , And give them some data .


It's that simple .


That's the end of the milestone . Let's look at the action plan . It's very simple , But it's certainly not easy .


  • Choose one of the many blockchain friendly languages to learn , such as C++,Javascript,C#,Go etc. .


( Because of space , Let's start with the first part today , Next, please look forward to the contract , Anxious readers can also read the English version for the full text )


English full text :
https://blockgeeks.com/guides/blockchain-developer/


Reference reading :


This article is translated by high availability architecture , Technical originality and architecture practice article , Welcome to the official account menu 「 Contact us 」 To contribute .


High availability Architecture
Changing the way the Internet is built
版权声明:本文为[High availability architecture]所创,转载请带上原文链接,感谢。 https://netfreeman.com/2021/03/20210330185810655o.html