Top Related Projects
Substrate: The platform for blockchain innovators
:chains: A Framework for Building High Value Public Blockchains :sparkles:
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
Go implementation of the Ethereum protocol
Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.
Algorand's official implementation in Go.
Quick Overview
NEAR Protocol is a sharded, proof-of-stake, layer-one blockchain that is designed to provide a scalable, developer-friendly platform for decentralized applications. The nearcore repository contains the reference implementation of the NEAR protocol, written primarily in Rust.
Pros
- High scalability through sharding technology
- Developer-friendly with support for WebAssembly and multiple programming languages
- Fast transaction finality and low fees
- Strong focus on usability and accessibility for end-users
Cons
- Relatively new compared to more established blockchain platforms
- Smaller ecosystem and developer community compared to Ethereum
- Potential centralization concerns due to the current validator set size
- Less battle-tested in production environments compared to older blockchains
Code Examples
// Example of creating a new NEAR account
use near_sdk::json_types::U128;
use near_sdk::{env, near_bindgen, AccountId, Balance, Promise};
#[near_bindgen]
pub struct Contract {}
#[near_bindgen]
impl Contract {
#[payable]
pub fn create_account(&mut self, new_account_id: AccountId, new_public_key: String) -> Promise {
Promise::new(new_account_id)
.create_account()
.add_full_access_key(env::signer_account_pk())
.transfer(env::attached_deposit())
}
}
This example demonstrates how to create a new NEAR account using a smart contract.
// Example of a simple token transfer
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::{env, near_bindgen, AccountId, Balance};
#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
pub struct Token {
balances: std::collections::HashMap<AccountId, Balance>,
}
#[near_bindgen]
impl Token {
pub fn transfer(&mut self, to: AccountId, amount: Balance) {
let from = env::predecessor_account_id();
let from_balance = self.balances.get(&from).unwrap_or(&0);
assert!(amount <= *from_balance, "Insufficient funds");
self.balances.insert(from, from_balance - amount);
let to_balance = self.balances.get(&to).unwrap_or(&0);
self.balances.insert(to, to_balance + amount);
}
}
This example shows a basic token transfer implementation in a NEAR smart contract.
Getting Started
To get started with NEAR development:
-
Install the NEAR CLI:
npm install -g near-cli
-
Create a new NEAR project:
near dev-deploy
-
Interact with your contract:
near call <contract_name> <method_name> '{"arg1": "value1"}' --accountId <your_account>.testnet
For more detailed instructions, visit the NEAR documentation.
Competitor Comparisons
Substrate: The platform for blockchain innovators
Pros of Substrate
- More flexible and modular architecture, allowing for easier customization of blockchain components
- Larger ecosystem and community support, with numerous projects built on Substrate
- Comprehensive documentation and developer resources
Cons of Substrate
- Steeper learning curve due to its complexity and extensive features
- Potentially higher resource requirements for development and deployment
- Less optimized for specific use cases compared to purpose-built blockchains
Code Comparison
Nearcore (Rust):
pub fn process_block(
&mut self,
block: &Block,
provenance: Provenance,
) -> Result<Option<near_chain::Error>, Error> {
// Block processing logic
}
Substrate (Rust):
fn execute_block(
&self,
block: Block<Self::Block>,
state: &mut Self::State,
) -> Result<(), Self::Error> {
// Block execution logic
}
Both projects use Rust and implement similar block processing functions, but Substrate's approach is more generic and adaptable to different blockchain architectures.
:chains: A Framework for Building High Value Public Blockchains :sparkles:
Pros of Cosmos SDK
- Modular architecture allows for easier customization and extension
- Robust interoperability features with IBC protocol
- Large and active developer community
Cons of Cosmos SDK
- Steeper learning curve due to complex architecture
- Potentially slower development cycle for simple applications
- Higher resource requirements for running full nodes
Code Comparison
Cosmos SDK (Go):
func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}
NEAR Core (Rust):
pub fn new(
home_dir: &Path,
config: NearConfig,
genesis_validation: GenesisValidationMode,
) -> anyhow::Result<NearNode> {
let store = create_store(&home_dir);
let runtime = NightshadeRuntime::from_config(store, &config);
// ... (additional initialization code)
}
The code snippets showcase different approaches to blockchain initialization. Cosmos SDK uses a modular system with dependency injection, while NEAR Core employs a more direct initialization process. This reflects the architectural differences between the two platforms.
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
Pros of Solana
- Higher transaction throughput and lower latency
- More established ecosystem with larger developer community
- Advanced features like on-chain programs and parallel transaction processing
Cons of Solana
- Higher hardware requirements for validators
- More centralized due to fewer validator nodes
- Potential for network instability during high-load periods
Code Comparison
Solana (Rust):
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
// Process instruction logic
}
NEAR (Rust):
#[near_bindgen]
impl Contract {
pub fn some_method(&mut self, param: String) -> String {
// Method implementation
}
}
Both projects use Rust for their core implementations, but Solana focuses on low-level instruction processing, while NEAR uses a higher-level contract-oriented approach. Solana's code tends to be more performance-oriented, while NEAR's is more developer-friendly.
Solana's architecture allows for parallel transaction processing, contributing to its high throughput. NEAR, on the other hand, emphasizes usability and cross-contract calls, making it easier for developers to build complex applications.
Go implementation of the Ethereum protocol
Pros of go-ethereum
- More mature and battle-tested codebase with a larger developer community
- Extensive documentation and resources for developers
- Wider adoption and ecosystem support
Cons of go-ethereum
- Higher gas fees and slower transaction processing
- More complex smart contract development due to Solidity language
- Limited scalability compared to NEAR's sharding approach
Code Comparison
go-ethereum (Ethereum):
func (s *Ethereum) Start() error {
if err := s.startEthService(); err != nil {
return err
}
return nil
}
nearcore (NEAR):
pub fn start_near(home_dir: &Path) -> anyhow::Result<NearNode> {
let near_config = load_config(home_dir)?;
NearNode::new(&near_config)
}
The code snippets show the entry points for starting the respective blockchain nodes. go-ethereum uses Go and follows a more object-oriented approach, while nearcore uses Rust and employs a functional programming style.
go-ethereum has a larger codebase and more complex architecture, reflecting its longer development history and broader feature set. nearcore, being newer, has a more streamlined codebase focused on scalability and performance.
Both projects are open-source and actively maintained, but go-ethereum has a larger contributor base due to Ethereum's wider adoption and longer presence in the market.
Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.
Pros of Fabric
- Enterprise-focused with modular architecture and pluggable components
- Supports private transactions and channels for data isolation
- Mature ecosystem with extensive documentation and enterprise adoption
Cons of Fabric
- More complex setup and configuration compared to NEAR
- Slower transaction finality due to consensus mechanism
- Limited scalability in high-throughput scenarios
Code Comparison
Fabric (Chaincode in Go):
func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface, id string, value int) error {
asset := Asset{ID: id, Value: value}
assetJSON, err := json.Marshal(asset)
if err != nil {
return err
}
return ctx.GetStub().PutState(id, assetJSON)
}
NEAR (Smart Contract in Rust):
#[near_bindgen]
impl Contract {
pub fn create_asset(&mut self, asset_id: String, value: u64) {
let asset = Asset { id: asset_id.clone(), value };
self.assets.insert(&asset_id, &asset);
}
}
Both examples demonstrate creating an asset, but Fabric uses a lower-level API with JSON serialization, while NEAR leverages high-level abstractions provided by the NEAR SDK.
Algorand's official implementation in Go.
Pros of go-algorand
- Written in Go, which is known for its simplicity and efficiency
- Extensive documentation and well-organized codebase
- Strong focus on security and formal verification
Cons of go-algorand
- Smaller developer community compared to NEAR
- Less flexible smart contract capabilities
- Lower transaction throughput than NEAR
Code Comparison
Algorand (Go):
func (node *AlgorandFullNode) Start() error {
node.mu.Lock()
defer node.mu.Unlock()
if node.running {
return fmt.Errorf("node already running")
}
node.running = true
go node.run()
return nil
}
NEAR (Rust):
pub fn start(&mut self) -> Result<()> {
if self.is_running() {
return Err(Error::AlreadyStarted);
}
self.running = true;
self.spawn_workers()?;
Ok(())
}
Both examples show node startup functions, highlighting differences in language syntax and error handling approaches. Algorand uses Go's concurrency model with goroutines, while NEAR leverages Rust's ownership system and Result type for error handling.
The comparison illustrates the different programming paradigms and design choices between the two projects, reflecting their respective language ecosystems and architectural decisions.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Reference implementation of NEAR Protocol
About NEAR
NEAR's purpose is to enable community-driven innovation to benefit people around the world.
To achieve this purpose, NEAR provides a developer platform where developers and entrepreneurs can create apps that put users back in control of their data and assets, which is the foundation of "Open Web" movement.
One of the components of NEAR is the NEAR Protocol, an infrastructure for server-less applications and smart contracts powered by a blockchain. NEAR Protocol is built to deliver usability and scalability of modern PaaS like Firebase at fraction of the prices that blockchains like Ethereum charge.
Overall, NEAR provides a wide range of tools for developers to easily build applications:
- JS Client library to connect to NEAR Protocol from your applications.
- Rust and JavaScript/TypeScript SDKs to write smart contracts and stateful server-less functions.
- Several essential repositories to guide you in building across Near's Open Web Platform.
- Numerous examples with links to hack on them right inside your browser.
- Lots of documentation, with Tutorials and API docs.
Join the Network
The easiest way to join the network, is by using the nearup
command, which you can install as follows:
pip3 install --user nearup
You can join all the active networks:
- mainnet:
nearup run mainnet
- testnet:
nearup run testnet
- betanet:
nearup run betanet
Check the nearup
repository for more details on how to run with or without docker.
To learn how to become validator, checkout documentation.
Contributing
The workflow and details of setup to contribute are described in CONTRIBUTING.md, and security policy is described in SECURITY.md. To propose new protocol changes or standards use Specification & Standards repository.
Getting in Touch
We use Zulip for semi-synchronous technical discussion, feel free to chime in:
For non-technical discussion and overall direction of the project, see our Discourse forum:
Top Related Projects
Substrate: The platform for blockchain innovators
:chains: A Framework for Building High Value Public Blockchains :sparkles:
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
Go implementation of the Ethereum protocol
Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.
Algorand's official implementation in Go.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot