Convert Figma logo to code with AI

hyperledger-solang logosolang

Solidity Compiler for Solana and Polkadot

1,283
221
1,283
109

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,929

Pythonic Smart Contract Language for the EVM

Quick Overview

Solang is a Solidity compiler designed for the Solana blockchain. It aims to provide a seamless transition for Ethereum developers to the Solana ecosystem by allowing them to write smart contracts in Solidity and deploy them on Solana. Solang supports most Solidity language features while optimizing for Solana's unique architecture.

Pros

  • Enables Ethereum developers to leverage their existing Solidity skills on Solana
  • Supports multiple target blockchains, including Solana and Substrate
  • Provides better performance and lower fees compared to Ethereum
  • Actively maintained and developed by the Hyperledger community

Cons

  • Not all Solidity features are fully supported or optimized for Solana
  • May require some adjustments to existing Solidity code for optimal performance
  • Documentation and ecosystem support are still evolving
  • Potential learning curve for understanding Solana-specific concepts

Code Examples

  1. Basic Solidity contract compiled with Solang:
contract HelloWorld {
    string public message;

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

    function update(string memory newMessage) public {
        message = newMessage;
    }
}
  1. Using Solana-specific features in Solang:
import 'solana';

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

    function transfer(address recipient, uint64 amount) public {
        recipient.transfer(amount);
    }
}
  1. Interacting with Solana Program Derived Addresses (PDAs):
import 'solana';

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

    function interactWithPDA(address pda) public {
        pda.call(abi.encodeWithSignature("someFunction()"));
    }
}

Getting Started

To get started with Solang:

  1. Install Solang:

    cargo install solang
    
  2. Compile a Solidity file for Solana:

    solang compile --target solana example.sol
    
  3. Deploy the compiled contract using Solana CLI or a compatible development framework.

For more detailed instructions and examples, refer to the 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 large community for support
  • More mature and feature-rich language with established best practices

Cons of Solidity

  • Limited to Ethereum and EVM-compatible blockchains
  • Steeper learning curve for developers new to blockchain
  • Potential security vulnerabilities due to its Turing-completeness

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

The code structure is similar, but Solang doesn't require a pragma statement and uses a slightly different syntax. Solang aims to be compatible with Solidity while offering additional features and optimizations for different blockchain platforms.

5,296

Static Analyzer for Solidity and Vyper

Pros of Slither

  • Extensive static analysis capabilities for Solidity smart contracts
  • Large number of built-in detectors for common vulnerabilities
  • Active community and frequent updates

Cons of Slither

  • Limited to Solidity language analysis
  • May produce false positives in some cases
  • Steeper learning curve for advanced features

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
  • Solang is primarily a Solidity compiler for various blockchain targets
  • Slither is written in Python, while Solang is implemented in Rust
  • Solang provides more extensive language support beyond Solidity
  • Slither offers a wider range of built-in security checks and detectors

Symbolic execution tool

Pros of Manticore

  • Powerful symbolic execution engine for analyzing smart contracts and binaries
  • Supports multiple platforms including EVM, WASM, and x86
  • Extensive API for custom analysis and integration with other tools

Cons of Manticore

  • Steeper learning curve compared to Solang
  • May require more computational resources for complex analyses
  • Limited to analysis and doesn't compile or generate code

Code Comparison

Manticore (Python API for EVM analysis):

from manticore.ethereum import ManticoreEVM

m = ManticoreEVM()
contract = m.solidity_create_contract("MyContract.sol")
symbolic_value = m.make_symbolic_value()
contract.function(symbolic_value)

Solang (Solidity compilation):

solang compile --target substrate MyContract.sol

Solang focuses on compiling Solidity to various targets, while Manticore provides a framework for in-depth analysis of smart contracts and binaries. Solang is more straightforward for developers familiar with Solidity, whereas Manticore offers powerful analysis capabilities but requires more expertise to utilize effectively.

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 maintenance by a dedicated team

Cons of openzeppelin-contracts

  • Focused primarily on Ethereum and EVM-compatible chains
  • May include unnecessary complexity for simple projects

Code Comparison

openzeppelin-contracts:

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

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

solang:

contract MyToken {
    string public name = "MyToken";
    string public symbol = "MTK";
    uint8 public decimals = 18;
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;

    constructor(uint256 initialSupply) {
        totalSupply = initialSupply;
        balanceOf[msg.sender] = initialSupply;
    }
}

Summary

openzeppelin-contracts provides a comprehensive set of battle-tested smart contract components for Ethereum and EVM-compatible chains, offering security and standardization. solang, on the other hand, is a Solidity compiler for Substrate, Solana, and other blockchain platforms, providing more flexibility in target platforms but with less pre-built contract functionality.

4,929

Pythonic Smart Contract Language for the EVM

Pros of Vyper

  • More Pythonic syntax, making it easier for Python developers to transition
  • Designed with a focus on security and simplicity, reducing potential vulnerabilities
  • Stricter language rules that prevent certain types of attacks common in Solidity

Cons of Vyper

  • Less mature ecosystem compared to Solidity, with fewer tools and resources
  • Limited support for complex features like inheritance, which can be restrictive for some developers
  • Smaller community and fewer production-level projects using Vyper

Code Comparison

Vyper example:

@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 example:

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 comparison shows that Vyper's syntax is more Python-like, with indentation-based scoping and type annotations. Solang, being Solidity-compatible, uses a C-style syntax with curly braces and semicolons. Both achieve similar functionality, but Vyper's code appears more concise and readable for those familiar with Python.

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