NEAR Protocol - scalable and usable blockchain
NEAR Protocol is a new smart-contract platform that delivers scalability and usability.
Through sharding it aims to linearly scale with number of validation nodes on the network.
Leveraging WebAssembly, TypeScript, more sane contract management, ephemeral accounts and many other advancement, NEAR makes using blockchain protocol for developers and consumers way easier compared to competitors.
Status
Project is currently under heavy development. Please see Issues and Milestones to checkout the current progress and work items.
High level milestones:
- DevNet: a tool with fully working State Transition + WebAssembly.
- MVB: Minimum viable blockchain with smart contracts, supporting TxFlow and on chain governance.
- Shard chains: support for fully scalable sharded blockchain.
Building
Setup rust
$ curl https://sh.rustup.rs -sSf | sh
$ rustup component add clippy-previewYou may need to activate the environment via . ~/.cargo/env to use cargo.
Install dependencies
Mac OS:
brew install protobufUbuntu:
apt-get install protobuf-compilerBuild & Run from source code
# Download NEAR Core code.
git clone https://github.com/nearprotocol/nearcore
cd nearcoreIt will build the first time and then run:
cargo runTesting
In order to run tests currently, you must setup the following:
# sudo may be required if you are not testing with a python virtual environment
pip install protobufLogging
For runnable apps (devnet, nearcore, etc.), you can use
the --log-level option to configure the log level across all internal crates.
You can also use the RUST_LOG environment variable, with env_logger
semantics
to override the log level for specific targets. RUST_LOG can also be used in
integration tests which spawn runnable apps.
Example:
$ RUST_LOG=runtime=debug cargo run -- --log-level warnTo add new target (e.g. info!(target: "my target", "hello")),
add the desired target to the list in node/cli/src/service.rs in configure_logging function.
Simple Install for Mac and Linux
Coming soon.
DevNet
DevNet is a development tool that runs WebAssembly and State transition without running blockchain/consensus functionality.
First, generate key pair (saves a key pair into keystore folder to use with rpc.py):
cargo run --package keystore -- keygen --test-seed alice.nearThen build and run DevNet:
cargo run --release --package=devnetUse -- --log-level debug to see more information about RPC and transaction processing.
Try submitting transactions or views via JSON RPC:
# See usage of rpc helper script
./scripts/rpc.py --help
# Get usage of sub command
./scripts/rpc.py send_money --help
# Send money
./scripts/rpc.py send_money -r bob -a 1
# Deploy a smart contract
./scripts/rpc.py deploy test_contract tests/add.wasm
# Call method 'run_test' for contract 'test_contract'
./scripts/rpc.py schedule_function_call test_contract add --args '{"a": 10, "b": 20}'
# Call view function 'run_test' for contract 'test_contract'
./scripts/rpc.py call_view_function test_contract add --args '{"a": 10, "b": 20}'
# View state for Bob's account
./scripts/rpc.py view_account -a bob
# Create an account
./scripts/rpc.py create_account cindy 1
# View full state db of the contract
./scripts/rpc.py view_state test_contractDevelopment
If you are planning to contribute, there are few more things to setup
Setup git hooks
./scripts/setup_hooks.shSetup rustfmt for your editor (optional)
Installation instructions here
Lints
We currently use clippy to enforce certain standards.
This check is run automatically during CI builds, and in a pre-commit
hook. You can run do a clippy check with ./scripts/run_clippy.sh.
Running TestNet locally
Navigate to the root of the project. To start the network from a new state remove the storage:
rm -rf test1 test2
Launch the boot node:
cargo run -- --p2p_port 30333 --rpc_port 3030 --base-path=test1 --test-network-key-seed 1 --chain-spec-file ./node/configs/res/testnet_chain.json
Then launch the secondary node:
cargo run -- --p2p_port 30334 --rpc_port 3031 --base-path=test2 --boot-node /ip4/127.0.0.1/tcp/30333/p2p/QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK --chain-spec-file ./node/configs/res/testnet_chain.json --account-id bob.near
Wait until both nodes print the following (otherwise retry the previous steps):
New external node address ...
Submit account creation transaction on one node:
./scripts/rpc.py create_account jason 1 --public-key 22skMptHjFWNyuEWY22ftn2AbLPSYpmYwGJRGwpNHbTV
Verify that the account was created by checking it on the other node:
./scripts/rpc.py view_account -a jason -u http://127.0.0.1:3031/