Convert Figma logo to code with AI

solana-labs logosolana

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.

12,919
4,133
12,919
346

Top Related Projects

Go implementation of the Ethereum protocol

Reference client for NEAR Protocol

:chains: A Framework for Building High Value Public Blockchains :sparkles:

Algorand's official implementation in Go.

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.

Quick Overview

Solana is a high-performance blockchain platform designed for decentralized applications and cryptocurrencies. It aims to provide fast, secure, and scalable solutions for the blockchain industry, with a focus on low transaction costs and high throughput.

Pros

  • Extremely high transaction speed and throughput (up to 65,000 transactions per second)
  • Low transaction costs, making it suitable for micro-transactions
  • Energy-efficient Proof of History (PoH) consensus mechanism
  • Strong developer ecosystem and growing adoption in DeFi and NFT spaces

Cons

  • Relatively centralized compared to some other blockchain platforms
  • Occasional network instability and outages
  • Steep learning curve for developers due to unique architecture
  • Limited smart contract functionality compared to platforms like Ethereum

Code Examples

  1. Creating a simple Solana program (smart contract):
use solana_program::{
    account_info::AccountInfo,
    entrypoint,
    entrypoint::ProgramResult,
    pubkey::Pubkey,
    msg,
};

entrypoint!(process_instruction);

pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    msg!("Hello, Solana!");
    Ok(())
}
  1. Connecting to a Solana cluster using JavaScript:
const { Connection, clusterApiUrl } = require('@solana/web3.js');

const connection = new Connection(clusterApiUrl('devnet'));
console.log('Connected to Solana devnet');
  1. Creating and sending a simple transaction:
const { Connection, Transaction, SystemProgram, Keypair, sendAndConfirmTransaction } = require('@solana/web3.js');

async function sendSol() {
  const connection = new Connection(clusterApiUrl('devnet'));
  const from = Keypair.generate();
  const to = Keypair.generate().publicKey;

  const transaction = new Transaction().add(
    SystemProgram.transfer({
      fromPubkey: from.publicKey,
      toPubkey: to,
      lamports: 1000000,
    })
  );

  const signature = await sendAndConfirmTransaction(
    connection,
    transaction,
    [from]
  );
  console.log('Transaction sent:', signature);
}

sendSol();

Getting Started

To start developing on Solana:

  1. Install Rust and the Solana CLI:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    sh -c "$(curl -sSfL https://release.solana.com/v1.10.32/install)"
    
  2. Set up a new Solana project:

    cargo init --lib my_solana_project
    cd my_solana_project
    
  3. Add Solana dependencies to your Cargo.toml:

    [dependencies]
    solana-program = "1.10.32"
    
  4. Write your Solana program in src/lib.rs and build:

    cargo build-bpf
    
  5. Deploy your program to the Solana devnet:

    solana program deploy target/deploy/my_solana_project.so
    

Competitor Comparisons

Go implementation of the Ethereum protocol

Pros of go-ethereum

  • Mature codebase with extensive documentation and community support
  • Robust smart contract functionality and EVM compatibility
  • Well-established ecosystem with numerous tools and libraries

Cons of go-ethereum

  • Lower transaction throughput compared to Solana
  • Higher gas fees and slower transaction finality
  • More complex architecture, potentially harder for new developers to grasp

Code Comparison

go-ethereum (Ethereum)

func (s *Ethereum) Start() error {
    if err := s.engine.Start(s.blockchain, s.config.Chain.Config, s.ethDb, s.config.Miner.Notify, s.config.Miner.Noverify); err != nil {
        return err
    }
    // Start the RPC service
    s.netRPCService = ethapi.NewPublicNetAPI(s.p2pServer, s.NetVersion())
    return nil
}

Solana

pub fn new_with_bank_forks(
    genesis_config: &GenesisConfig,
    bank_forks: BankForks,
    block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
    rpc_config: JsonRpcConfig,
    pubsub_config: PubSubConfig,
) -> Self {
    let bank = bank_forks.working_bank();
    let transaction_sender = Arc::new(RwLock::new(TransactionSender::new(bank.clone())));
    // ... (additional initialization code)
}

The code snippets showcase differences in language (Go vs. Rust) and initialization processes for each blockchain platform.

Reference client for NEAR Protocol

Pros of NEAR Core

  • More accessible for developers with Rust experience
  • Simpler sharding mechanism for improved scalability
  • Focus on user-friendly features like human-readable account names

Cons of NEAR Core

  • Smaller ecosystem and developer community compared to Solana
  • Less battle-tested in high-throughput scenarios
  • Fewer integrations with existing DeFi protocols and tools

Code Comparison

NEAR Core (Rust):

pub fn process_transaction(
    &mut self,
    tx: SignedTransaction,
    state_root: &StateRoot,
) -> Result<ExecutionOutcome, RuntimeError> {
    // Transaction processing logic
}

Solana (Rust):

pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    // Instruction processing logic
}

Both projects use Rust, but NEAR Core's API tends to be more high-level and abstracted, while Solana's is more low-level and performance-focused. NEAR Core emphasizes ease of use for developers, while Solana prioritizes raw transaction throughput and minimal latency.

:chains: A Framework for Building High Value Public Blockchains :sparkles:

Pros of Cosmos SDK

  • Modular architecture allows for easier customization and development of specialized blockchains
  • Supports Inter-Blockchain Communication (IBC) protocol, enabling interoperability between different chains
  • Provides a more flexible consensus mechanism through Tendermint Core

Cons of Cosmos SDK

  • Generally slower transaction processing compared to Solana's high-performance architecture
  • Less established ecosystem and smaller developer community than Solana
  • Higher complexity for developers due to its modular nature and customization options

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)
}

Solana (Rust):

pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    let instruction = TokenInstruction::unpack(instruction_data)?;
    match instruction {
        TokenInstruction::InitializeMint { decimals, mint_authority, freeze_authority } => {
            msg!("Instruction: InitializeMint");
            process_initialize_mint(accounts, decimals, mint_authority, freeze_authority)
        },
        // ... other instructions
    }
}

Algorand's official implementation in Go.

Pros of go-algorand

  • Written in Go, which is known for its simplicity and efficiency
  • Implements a pure proof-of-stake consensus mechanism, potentially more energy-efficient
  • Focuses on scalability and fast transaction finality

Cons of go-algorand

  • Smaller developer community compared to Solana
  • Less established ecosystem and fewer dApps
  • Lower transaction throughput than Solana (though still high compared to many blockchains)

Code Comparison

Solana (Rust):

pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    // Process instruction logic
}

go-algorand (Go):

func (app *Application) OnCompletion(txn transactions.Transaction, ac applications.AppContext) error {
    // Process transaction logic
    return nil
}

Both examples show entry points for processing transactions or instructions, but Solana's approach is more low-level, dealing directly with accounts and instruction data, while Algorand's is more abstracted, working with higher-level transaction objects.

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.

Pros of Aptos

  • Utilizes Move, a safer and more efficient smart contract language
  • Implements parallel execution for improved transaction throughput
  • Offers a more modular architecture, facilitating easier upgrades and maintenance

Cons of Aptos

  • Less battle-tested in production environments compared to Solana
  • Smaller developer ecosystem and community support
  • Currently has lower transaction speeds than Solana's peak performance

Code Comparison

Aptos (Move language):

module HelloWorld {
    use std::string;

    public fun hello(): string::String {
        string::utf8(b"Hello, World!")
    }
}

Solana (Rust):

use solana_program::{
    account_info::AccountInfo,
    entrypoint,
    entrypoint::ProgramResult,
    pubkey::Pubkey,
    msg,
};

entrypoint!(process_instruction);

pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    msg!("Hello, World!");
    Ok(())
}

The Aptos example showcases the Move language's simplicity and safety features, while the Solana example demonstrates the more complex structure required for Solana programs written in Rust.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Solana

Solana crate Solana documentation Build status codecov

Building

1. Install rustc, cargo and rustfmt.

$ curl https://sh.rustup.rs -sSf | sh
$ source $HOME/.cargo/env
$ rustup component add rustfmt

When building the master branch, please make sure you are using the latest stable rust version by running:

$ rustup update

When building a specific release branch, you should check the rust version in ci/rust-version.sh and if necessary, install that version by running:

$ rustup install VERSION

Note that if this is not the latest rust version on your machine, cargo commands may require an override in order to use the correct version.

On Linux systems you may need to install libssl-dev, pkg-config, zlib1g-dev, protobuf etc.

On Ubuntu:

$ sudo apt-get update
$ sudo apt-get install libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang cmake make libprotobuf-dev protobuf-compiler

On Fedora:

$ sudo dnf install openssl-devel systemd-devel pkg-config zlib-devel llvm clang cmake make protobuf-devel protobuf-compiler perl-core

2. Download the source code.

$ git clone https://github.com/solana-labs/solana.git
$ cd solana

3. Build.

$ ./cargo build

Testing

Run the test suite:

$ ./cargo test

Starting a local testnet

Start your own testnet locally, instructions are in the online docs.

Accessing the remote development cluster

  • devnet - stable public cluster for development accessible via devnet.solana.com. Runs 24/7. Learn more about the public clusters

Benchmarking

First, install the nightly build of rustc. cargo bench requires the use of the unstable features only available in the nightly build.

$ rustup install nightly

Run the benchmarks:

$ cargo +nightly bench

Release Process

The release process for this project is described here.

Code coverage

To generate code coverage statistics:

$ scripts/coverage.sh
$ open target/cov/lcov-local/index.html

Why coverage? While most see coverage as a code quality metric, we see it primarily as a developer productivity metric. When a developer makes a change to the codebase, presumably it's a solution to some problem. Our unit-test suite is how we encode the set of problems the codebase solves. Running the test suite should indicate that your change didn't infringe on anyone else's solutions. Adding a test protects your solution from future changes. Say you don't understand why a line of code exists, try deleting it and running the unit-tests. The nearest test failure should tell you what problem was solved by that code. If no test fails, go ahead and submit a Pull Request that asks, "what problem is solved by this code?" On the other hand, if a test does fail and you can think of a better way to solve the same problem, a Pull Request with your solution would most certainly be welcome! Likewise, if rewriting a test can better communicate what code it's protecting, please send us that patch!

Disclaimer

All claims, content, designs, algorithms, estimates, roadmaps, specifications, and performance measurements described in this project are done with the Solana Labs, Inc. (“SL”) good faith efforts. It is up to the reader to check and validate their accuracy and truthfulness. Furthermore, nothing in this project constitutes a solicitation for investment.

Any content produced by SL or developer resources that SL provides are for educational and inspirational purposes only. SL does not encourage, induce or sanction the deployment, integration or use of any such applications (including the code comprising the Solana blockchain protocol) in violation of applicable laws or regulations and hereby prohibits any such deployment, integration or use. This includes the use of any such applications by the reader (a) in violation of export control or sanctions laws of the United States or any other applicable jurisdiction, (b) if the reader is located in or ordinarily resident in a country or territory subject to comprehensive sanctions administered by the U.S. Office of Foreign Assets Control (OFAC), or (c) if the reader is or is working on behalf of a Specially Designated National (SDN) or a person subject to similar blocking or denied party prohibitions.

The reader should be aware that U.S. export control and sanctions laws prohibit U.S. persons (and other persons that are subject to such laws) from transacting with persons in certain countries and territories or that are on the SDN list. Accordingly, there is a risk to individuals that other persons using any of the code contained in this repo, or a derivation thereof, may be sanctioned persons and that transactions with such persons would be a violation of U.S. export controls and sanctions law.

NPM DownloadsLast 30 Days