NeoSPCC released NeoGo node that fully supports dBFT consensus
NEO builds smart economy and we at NEO SPCC help them with that big challenge.
In our blog you might find the latest articles on how we run NeoFS public Testnet but it’s not the only thing we’re working on.
NEO GO
As you know Neo network is composed of nodes. These nodes as of now have several implementations:
This article is about the last one since we’re developing it at NEO SPCC. By the way a few weeks ago we released a node that fully supports dBFT consensus. This article will help you to get an idea of how everything is tied up and being able to start neo-go node, write smart contract and deploy it.
What is a node?
The main goal of a node is to interact with other nodes (through P2P) and synchronize blocks in the network. It also allows user to compile and run smart contracts within the blockchain network.
Node consists of Client (CLI), Network layer, Consensus, Virtual Machine, Compiler and Blockchain. Let’s take a closer look at each of them.
Client
Client (CLI) allows users to run commands from the terminal. These commands can be divided in 4 categories:
- server operations
- smart contract operations
- vm operations
- wallet operations
For example to connect node to the running private network you can use this command:
$ ./bin/neo-go node -p
Here you can find more information about Private Network and how to start it. Simply speaking private network is a network that you run locally. Follow the link if you are interested in more detailed description.
Another usage example is to neo-go smart-contract compile:
$ ./bin/neo-go vm
NEO-GO-VM >
Once we run this command we will get an interface to interact with virtual machine. To get a list of all supported operations you just use `help`:
As you can see there are a lot of options to play with. Let’s take some smart contract and compile it:
Use command `loadgo` to compile it:
And there you can see how many instructions were generated and even if you are interested in opcodes of current program you can dump them:
Later we will use this compiled contract in a workshop.
More information how to use cli you can find here.
Network
Network layer is one of the most important parts of the node. In our case we have P2P protocol which allows nodes to communicate with each other and RPC — which is used for getting some information from node like balance, accounts, current state, etc.
Here is the document where you can find supported RPC calls.
Consensus
Consensus is a mechanism allowing nodes to agree on a specific value (block in case of blockchain). Node uses Go implementation of dBFT algorithm.
Compiler
Compiler allows to build byte code, so you can write Smart Contract in your favourite Golang. All the output you saw in these example above was generated by the compiler.
Virtual machine
Virtual machine runs compiled byte code. NeoVM is a stack-based virtual machine. It has 2 stacks for performing computation.
Blockchain
And what is the Blockchain piece? It’s quite a big one since it contains operations with accepting/validation transactions, signing transactions, working with accounts, assets, storing blocks in database (or in cache).
Network
There are 3 types of network.
Private net — it’s the private one which you can run locally. Testnet and Mainnet where much of the nodes across the world now running. NEO has a nice monitor where you can find particular node running in the blockchain network.
Workshop
Now it’s time to run your private network. Connect neo-go node to it, write smart contract and deploy it. Let’s go!
Step 1
Download neo-go and build it
git clone https://github.com/nspcc-dev/neo-go.git
$ cd neo-go
$ make build
Step 2
Run local privatenet (more details can be found here)
$ make env_image
$ make env_up
Running privatenet:
$ make env_up
In case you need to shutdown environment you can use:
$ make env_down
Step 3
Create basic Hello World smart contract:
Or get in from git workshop file.
And save it as `1-print.go`
Create configuration for it:
https://github.com/nspcc-dev/neo-go-sc-wrkshp/blob/master/1-print.yml
Step 4
Run “Hello World” contract
$ ./bin/neo-go contract compile -i 1-print.go
Where
- ./bin/neo-go runs neo-go.
- contract compile command with arguments in neo-go https://github.com/nspcc-dev/neo-go/blob/master/cli/smartcontract/smart_contract.go#L43
- -i 1-print.go path to smart contract
Result:
$ ./bin/neo-go contract compile -i 1-print.go
51c56b0d48656c6c6f2c20776f726c6421680f4e656f2e52756e74696d652e4c6f67616c7566
You will see compiled contract in console which is saved as `1-print.avm`.
Step 5
Start neo-go node which will connect to previously started privatenet:
$ ./bin/neo-go node — privatenet
Deploy smart contract:
$ ./bin/neo-go contract deploy -i 1-print.avm -c neo-go.yml -e http://localhost:20331 -w KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr -g 100
Where:
- -i defines path to compiled AVM smart contract
- -e http://localhost:20331 defines RPC endpoint used for function call
- -w KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr is a WIF
- -g 100 defines amount of GAS to be used for deploy operation
Result:
At this point your ‘Hello World’ contract is deployed and can be invoked. Let’s do it as a final step.
Step 6
Invoke smart contract:
$ ./bin/neo-go contract invokefunction -e http://localhost:20331 -w KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr -g 0.00001 6d1eeca891ee93de2b7a77eb91c26f3b3c04d6cf
Where
- contract invokefunction runs invoke with provided parameters
- -e http://localhost:20331 defines RPC endpoint used for function call
- -w KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr is a WIF
- -g 0.00001 defines amount of GAS to be used for invoke operation
- 6d1eeca891ee93de2b7a77eb91c26f3b3c04d6cf contract hash got as an output from the previous command (deployment in step 5)
Result:
In the console where you were running step #4 you will get:
Which means that this contract was executed.
This is it. There are only 6 steps to make deployment and invocation and they look easy, aren’t they?
If you want to play with more complicated scenario using storage you can follow our workshop.
Thank you and stay tuned!