Nebulas 101 - 01 Compile and Install Nebulas¶
The project code for Nebulas has been released in several versions and tested to run locally. You can download the Nebulas source code to compile the private chain locally.
To learn about Nebulas, please read the Nebulas Non-Technical White Paper.
To learn about the technology, please read the Nebulas Technical White Paper and the Nebulas github code.
Nebulas can only runs on Mac and Linux at this stage. The Windows version will be coming soon.
Golang Environment¶
Nebulas is implemented in Golang now.
| Components | Version | Description | | — | — | — | | Golang |
>
= 1.9.2 | The Go Programming Language |Mac OSX¶
Homebrew is recommended for installing golang on Mac.
# install
brew install go
# environment variables
export GOPATH=/path/to/workspace
Notice:GOPATH is a local golang working directory which could be decided by youself. After GOPATH is configured, your go projects need to be placed in GOPATH directory.
Linux¶
# download
wget https://dl.google.com/go/go1.9.3.linux-amd64.tar.gz
# extract
tar -C /usr/local -xzf go1.9.3.linux-amd64.tar.gz
# environment variables
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/path/to/workspace
Compile Nebulas¶
Download¶
Clone source code with the following commands.
# enter workspace
mkdir -p $GOPATH/src/github.com/nebulasio
cd $GOPATH/src/github.com/nebulasio
# download
git clone https://github.com/nebulasio/go-nebulas.git
# enter repository
cd go-nebulas
# master branch is most stable
git checkout master
Install RocksDB¶
OS X:
Install rocksdb via Homebrew
brew install rocksdb
Linux - Ubuntu
Install Dependencies
apt-get update apt-get -y install build-essential libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev
Install rocksdb by source code:
git clone https://github.com/facebook/rocksdb.git cd rocksdb && make shared_lib && make install-shared
Linux - Centos
Install Dependencies
yum -y install epel-release && yum -y update yum -y install gflags-devel snappy-devel zlib-devel bzip2-devel gcc-c++ libstdc++-devel
Install rocksdb by source code:
git clone https://github.com/facebook/rocksdb.git cd rocksdb & make shared_lib && make install-shared
Install Go Dependencies¶
Go dependencies in Go-Nebulas is managed by Dep.
| Components | Version | Description | | — | — | — |
Dep |
>
= 0.3.1 | Dep is a dependency management tool for Go. |Install Dep¶
Mac OSX
Install Dep via Homebrew
brew install dep brew upgrade dep
Linux
Install dep
cd /usr/local/bin/ wget https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64 ln -s dep-linux-amd64 dep
Download Dependencies¶
Switch to the root directory of the project to download dependencies for Go-Nebulas:
cd $GOPATH/src/github.com/nebulasio/go-nebulas
make dep
make dep
downloads lots of dependencies. It might take a long time to download for the first time. Some dependencies may fail to download. If you can not download, you can directly download the zipped dependency files generated by dep vendor.tar.gz and extract it to the nebulas root directory.vendor.tar.gz MD5: c2c1ff9311332f90e11fb81b48ca0984
Nebulas’s NVM (Nebulas Virtual Machine) depends on the V8 JavaScript engine. We’ve built the v8 dependencies for Mac/Linux. Run the following commands to install them.
cd $GOPATH/src/github.com/nebulasio/go-nebulas
make deploy-v8
Build Neb¶
You can now build the executable for Nebulas after golang dependencies and V8 dependency packages is installed.
Build under the project root directory:
cd $GOPATH/src/github.com/nebulasio/go-nebulas
make build
Once the building is complete,there will be a executable file neb
generated under the root directory.
Start NEB¶
Genesis Block¶
Before launching a new Nebulas chain, we have to define the configuration of genesis block.
Genesis Block Configuration¶
# Neb genesis text file. Scheme is defined in core/pb/genesis.proto.
meta {
# Chain identity
chain_id: 100
}
consensus {
dpos {
# Initial dynasty, including all initial miners
dynasty: [
[ miner address ],
...
]
}
}
# Pre-allocation of initial tokens
token_distribution [
{
address: [ allocation address ]
value: [ amount of allocation tokens ]
},
...
]
An example genesis.conf is located in conf/default/genesis.conf
.
Configuration¶
Before getting a neb node started, we have to define the configuration of this node.
Neb Node Configuration¶
# Neb configuration text file. Scheme is defined in neblet/pb/config.proto:Config.
# Network Configuration
network {
# For the first node in a new Nebulas chain, `seed` is not need.
# Otherwise, every node need some seed nodes to introduce it into the Nebulas chain.
# seed: ["/ip4/127.0.0.1/tcp/8680/ipfs/QmP7HDFcYmJL12Ez4ZNVCKjKedfE7f48f1LAkUc3Whz4jP"]
# P2p network service host. support mutiple ip and ports.
listen: ["0.0.0.0:8680"]
# The private key is used to generate a node ID. If you don't use the private key, the node will generate a new node ID.
# private_key: "conf/network/id_ed25519"
}
# Chain Configuration
chain {
# Network chain ID
chain_id: 100
# Database storage location
datadir: "data.db"
# Accounts' keystore files location
keydir: "keydir"
# The genesis block configuration
genesis: "conf/default/genesis.conf"
# Signature algorithm
signature_ciphers: ["ECC_SECP256K1"]
# Miner address
miner: "n1SAQy3ix1pZj8MPzNeVqpAmu1nCVqb5w8c"
# Coinbase address, all mining reward received by the above miner will be send to this address
coinbase: "n1FF1nz6tarkDVwWQkMnnwFPuPKUaQTdptE"
# The passphrase to miner's keystore file
passphrase: "passphrase"
}
# API Configuration
rpc {
# GRPC API port
rpc_listen: ["127.0.0.1:8684"]
# HTTP API port
http_listen: ["127.0.0.1:8685"]
# The module opened
http_module: ["api", "admin"]
}
# Log Configuration
app {
# Log level: [debug, info, warn, error, fatal]
log_level: "info"
# Log location
log_file: "logs"
# Open crash log
enable_crash_report: false
}
# Metrics Configuration
stats {
# Open node metrics
enable_metrics: false
# Influxdb configuration
influxdb: {
host: "http://localhost:8086"
db: "nebulas"
user: "admin"
password: "admin"
}
}
A lot of examples can be found in $GOPATH/src/github.com/nebulasio/go-nebulas/conf/
Run Nodes¶
The Nebulas chain you are running at this point is private and is different with official Testnet and Mainnet.
Start your first Nebulas node with the following commands.
cd $GOPATH/src/github.com/nebulasio/go-nebulas
./neb -c conf/default/config.conf
After starting, the following should be visible in the terminal:
By default, the node using conf/default/config.conf
won’t mine new blocks. Start your first Nebulas mining node with another commands.
cd $GOPATH/src/github.com/nebulasio/go-nebulas
./neb -c conf/example/miner.conf
After the node starts, if the connection with the seed node is successful, you can see the following log which is in log file logs/miner/neb.log
:
Note: You can start many nodes locally. Please make sure the ports in your node configurations won’t conflict with each other.