Pular para o conteúdo

Solang

The Solidity Compiler for Polkadot.

Solang is a Solidity compiler written in Rust and leveraging LLVM as its backend, is an essential tool for developers working with Polkadot parachains. Designed to be compatible with Solidity 0.8, Solang provides a seamless development experience, with optimizations tailored for the Polkadot ecosystem.

What Is Solang?

Solang is a modern Solidity compiler capable of targeting Polkadot parachains and Solana. By integrating with the contracts pallet, Solang enables developers to deploy Solidity smart contracts on Polkadot. Its compatibility with Solidity 0.8 ensures familiarity for Ethereum developers while addressing the nuances of Polkadot’s blockchain architecture. The tool emphasizes performance, security, and developer experience, making it a powerful choice for teams transitioning from Ethereum or exploring cross-chain opportunities.

Key Features of Solang for Polkadot

Solidity developers targeting Polkadot will encounter several important differences from Ethereum’s Solidity. Here are the primary distinctions and features:

  1. Address Type Adjustments: The address type in Polkadot is 32 bytes, unlike Ethereum’s 20 bytes. This aligns with Substrate’s definition of an “account.” Developers must use the syntax address"5GBWmgdFAMqm8ZgAHGobqDqX6tjLxJhv53ygjNtaaAn3sjeZ" to specify address literals.
  2. SCALE Encoding: All ABI encoding and decoding are performed using SCALE (Simple Concatenated Aggregate Little-Endian) encoding. This is a critical difference that developers must understand for Polkadot compatibility.
  3. Constructor Naming: Constructors in Solang can be explicitly named. If no name is provided, constructors will default to new in the generated metadata.
  4. Runtime Signature Verification: Unlike Ethereum, Polkadot does not support the ecrecover() function or other runtime cryptographic signature verification functions.
  5. Function Call Limitations: Only functions called via RPC can return values. Transactions calling functions cannot access return values, requiring alternative approaches to handle such logic.

Compiling Solidity for Polkadot with Solang

To compile Solidity smart contracts for Polkadot, developers can use the Solang command-line interface. As an example, the widely used flipper contract can be compiled as follows:

  1. Write the Solidity code to a file named flipper.sol.
  2. Run the following command:
Terminal window
solang compile --target polkadot flipper.sol

Built-in Functionality and Roadmap

Solang’s current feature set demonstrates its versatility and commitment to blockchain interoperability. With a high level of compatibility across chains, Solang ensures Solidity remains a go-to language for developers expanding into Polkadot and Solana ecosystems.

Conclusion

Solang represents a significant advancement for Solidity developers targeting Polkadot parachains. By addressing the unique requirements of Substrate and providing robust support for modern Solidity syntax, Solang empowers developers to build efficient, scalable, and secure smart contracts within the Polkadot ecosystem. With ongoing development and a clear roadmap, Solang is poised to become a cornerstone tool for cross-chain innovation.