Convert Figma logo to code with AI

hyperledger logosolang

Solidity Compiler for Solana and Polkadot

1,252
208
1,252
100

Top Related Projects

23,191

Solidity, the Smart Contract Programming Language

5,296

Static Analyzer for Solidity and Vyper

Symbolic execution tool

OpenZeppelin Contracts is a library for secure smart contract development.

4,837

Pythonic Smart Contract Language for the EVM

Quick Overview

Solang is a Solidity compiler designed for the Solana blockchain. It allows developers to write smart contracts in Solidity, a popular language for Ethereum development, and deploy them on Solana. This project aims to bridge the gap between Ethereum and Solana development ecosystems.

Pros

  • Enables Solidity developers to easily transition to Solana development
  • Leverages the existing Solidity ecosystem and tooling
  • Potentially improves performance of smart contracts on Solana
  • Supports multiple blockchain targets, including Substrate

Cons

  • May not fully utilize Solana-specific optimizations
  • Potential compatibility issues with some Solidity features
  • Learning curve for developers unfamiliar with Solana's architecture
  • Limited adoption compared to native Solana development tools

Code Examples

  1. Basic Solidity contract for Solana:
pragma solidity ^0.7.0;

contract HelloWorld {
    string public message;

    constructor(string memory initMessage) {
        message = initMessage;
    }

    function update(string memory newMessage) public {
        message = newMessage;
    }
}
  1. Using Solana-specific features:
pragma solidity ^0.7.0;

import 'solana';

contract SolanaSpecific {
    function getBalance(address account) public view returns (uint64) {
        return account.balance;
    }

    function transfer(address payable recipient, uint64 amount) public {
        recipient.transfer(amount);
    }
}
  1. Interacting with Solana Program Derived Addresses (PDAs):
pragma solidity ^0.7.0;

import 'solana';

contract PDAExample {
    function createPDA(bytes seed) public pure returns (address) {
        return address(new ProgramDerivedAddress(seed));
    }

    function interactWithPDA(address pda) public {
        // Interact with the PDA
        (bool success,) = pda.call("");
        require(success, "PDA interaction failed");
    }
}

Getting Started

To get started with Solang:

  1. Install Solang:

    cargo install --git https://github.com/hyperledger/solang
    
  2. Write your Solidity contract and save it as mycontract.sol

  3. Compile the contract for Solana:

    solang compile --target solana mycontract.sol
    
  4. Deploy the generated bytecode using Solana CLI or a compatible deployment tool

For more detailed instructions and advanced usage, refer to the official Solang documentation.

Competitor Comparisons

23,191

Solidity, the Smart Contract Programming Language

Pros of Solidity

  • Widely adopted and supported in the Ethereum ecosystem
  • Extensive documentation and community resources
  • More mature and battle-tested in production environments

Cons of Solidity

  • Limited to Ethereum and EVM-compatible chains
  • Slower development cycle for language updates and improvements
  • Potential security vulnerabilities due to its design choices

Code Comparison

Solidity:

pragma solidity ^0.8.0;

contract SimpleStorage {
    uint256 private storedData;

    function set(uint256 x) public {
        storedData = x;
    }
}

Solang:

contract SimpleStorage {
    uint256 storedData;

    function set(uint256 x) public {
        storedData = x;
    }
}

Key Differences

  • Solang supports multiple blockchain platforms, including Solana and Substrate
  • Solang uses LLVM as its backend, potentially offering better optimization
  • Solidity has a larger ecosystem of tools and libraries
  • Solang aims for better performance and more efficient code generation
  • Solidity has a longer track record and more extensive real-world usage

Both projects aim to provide smart contract development capabilities, but they target different ecosystems and have distinct design philosophies. The choice between them depends on the specific blockchain platform and development requirements of a project.

5,296

Static Analyzer for Solidity and Vyper

Pros of Slither

  • Extensive static analysis capabilities for Solidity smart contracts
  • Large community support and regular updates
  • Integrates well with CI/CD pipelines for automated security checks

Cons of Slither

  • Limited to Solidity language analysis
  • May produce false positives in some cases
  • Requires additional tools for comprehensive smart contract auditing

Code Comparison

Slither (Python-based analysis):

from slither.slither import Slither

slither = Slither('MyContract.sol')
print([c.name for c in slither.contracts])

Solang (Rust-based compilation):

use solang::{parse_and_resolve, Target};

let (ast, _) = parse_and_resolve(
    "contract foo { function bar() public {} }",
    Target::EVM,
    &[],
).unwrap();

Key Differences

  • Slither focuses on static analysis and vulnerability detection in Solidity
  • Solang is a Solidity compiler targeting various blockchain platforms
  • Slither is written in Python, while Solang is implemented in Rust
  • Solang provides more flexibility in target platforms, including Substrate
  • Slither offers a wider range of built-in security checks and detectors

Symbolic execution tool

Pros of Manticore

  • Supports multiple blockchain platforms (Ethereum, EOS, Tron)
  • Provides dynamic symbolic execution for thorough analysis
  • Offers a Python API for customizable analysis scripts

Cons of Manticore

  • Steeper learning curve due to its complex features
  • May be slower for large-scale analysis compared to Solang
  • Limited support for newer Solidity language features

Code Comparison

Manticore (Python API usage):

from manticore.ethereum import ManticoreEVM

m = ManticoreEVM()
contract = m.solidity_create_contract("MyContract.sol")
m.transaction(caller=0xAAA, address=contract.address, data=0x12345678)
m.finalize()

Solang (Solidity compilation):

solang compile --target substrate MyContract.sol

Key Differences

  • Manticore focuses on security analysis and vulnerability detection
  • Solang is primarily a Solidity compiler for various blockchain platforms
  • Manticore provides more in-depth analysis capabilities
  • Solang offers faster compilation and is more suitable for rapid development

Use Cases

  • Manticore: Security audits, vulnerability detection, and formal verification
  • Solang: Efficient Solidity compilation for multiple blockchain targets, including Substrate-based chains

OpenZeppelin Contracts is a library for secure smart contract development.

Pros of openzeppelin-contracts

  • Extensive library of secure, audited smart contract components
  • Well-documented and widely adopted in the Ethereum ecosystem
  • Regular updates and community-driven improvements

Cons of openzeppelin-contracts

  • Limited to Solidity and Ethereum-compatible blockchains
  • May include unnecessary features for simpler projects

Code Comparison

openzeppelin-contracts (ERC20 token):

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
        _mint(msg.sender, initialSupply);
    }
}

solang (Solana program):

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

entrypoint!(process_instruction);

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

Summary

openzeppelin-contracts offers a comprehensive suite of secure smart contract components for Ethereum and compatible chains, while solang provides a Solidity compiler for Solana. openzeppelin-contracts is more established in the Ethereum ecosystem, but solang enables Solidity-like development for Solana. The choice between them depends on the target blockchain and specific project requirements.

4,837

Pythonic Smart Contract Language for the EVM

Pros of Vyper

  • Designed for readability and simplicity, making it easier for developers to write secure smart contracts
  • Implements strong typing and bounds/overflow checking, enhancing contract security
  • Closely follows Python syntax, lowering the learning curve for Python developers

Cons of Vyper

  • Limited functionality compared to Solidity, with fewer features and less flexibility
  • Smaller ecosystem and community support, resulting in fewer resources and tools
  • Not as widely adopted in the Ethereum ecosystem, potentially limiting job opportunities

Code Comparison

Vyper:

@external
def transfer(_to: address, _value: uint256) -> bool:
    self.balanceOf[msg.sender] -= _value
    self.balanceOf[_to] += _value
    log Transfer(msg.sender, _to, _value)
    return True

Solang:

function transfer(address to, uint256 value) public returns (bool) {
    balanceOf[msg.sender] -= value;
    balanceOf[to] += value;
    emit Transfer(msg.sender, to, value);
    return true;
}

The code snippets demonstrate a basic token transfer function in both languages. Vyper's syntax is more Python-like and concise, while Solang (which compiles Solidity) follows a more C-like syntax typical of Solidity contracts.

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

Solang Logo

solang - Solidity Compiler for Solana and Polkadot

Discord CI Documentation Status license LoC

Welcome to Solang, a new Solidity compiler written in rust which uses llvm as the compiler backend. Solang can compile Solidity for Solana and Polkadot Parachains with the contracts pallet. Solang is source compatible with Solidity 0.8, with some caveats due to differences in the underlying blockchain.

Solang is under active development right now, and has extensive documentation.

Solana

Please follow the Solang Getting Started Guide.

Solang is part of the Solana Tools Suite (version v1.16.3 and higher). There is no need to install it separately.

Installation

Solang is available as a Brew cask for MacOS, with the following command:

brew install hyperledger/solang/solang

For other operating systems, please check the installation guide.

Build for Polkadot

Run the following command, selecting the flipper example available on Solang's repository:

solang compile --target polkadot examples/polkadot/flipper.sol

Alternatively if you want to use the solang container, run:

docker run --rm -it -v $(pwd):/sources ghcr.io/hyperledger/solang compile -v -o /sources --target polkadot /sources/flipper.sol

You will have a file called flipper.contract. You can use this directly in the Contracts UI, as if your smart contract was written using ink!.

Tentative roadmap

Solang has a high level of compatibility with many blockchains. We are trying to ensure the compiler stays up to date with the newest Solidity syntax and features. In addition, we focus on bringing new performance optimizations and improve developer experience. Here is a brief description of what we envision for the next versions.

V0.4

FeatureStatus
Improve management over optimization passesNot started
Adopt single static assignment for code generationIn progress
Support openzeppelin on Polkadot targetIn progress
Provide Solidity -> Polkadot porting guideNot started
Declare accounts for a Solidity function on SolanaIn progress
Tooling for calls between ink! <> solidityIn progress
Provide CLI for node interactionsDone

License

Apache 2.0