Solidity on Solana — What is Solang?
Overview
Solang, a Solidity compiler for Solana, was announced this week. This allows Ethereum Solidity developers to migrate to Solana and lessen the learning curve and time commitment needed to jump in. Previously, developers had to either use Rust, C, or Python.
The main purpose of releasing the Solang compiler for Solidity on Solana is to attract experienced developers who would normally have pause developing on Solana due to the gap in knowledge from learning Rust or another language to create programs.
In this article we will go over the following:
- What is a compiler?
- Benefits
- Impacts on Solana Programs
- Getting Started
What is a Compiler?
A compiler is a tool that translates high-level source code into a lower-level representation that can be executed by the target platform. For Solidity, the Solang compiler is needed for converting Solidity code into a format compatible with the Solana blockchain. It performs various stages to transform the code into optimized machine code or bytecode that can be executed on Solana. This ensures that Solidity developers can write and deploy their smart contracts on Solana with ease and efficiency.
In Solana, a commonly used programming language to create programs is Rust. Here is a graph detailing how Rust and Solidity are compiled to create program instructions for the Solana blockchain:
Benefits
As mentioned above, the primary aim of releasing Solang as a Solidity compiler on Solana is to attract experienced developers who might have hesitated to build on Solana due to the learning curve associated with Rust or other languages required to create programs on the platform. This allows Solidity developers to transition their skills and knowledge to Solana, unlocking the potential for them to build decentralized applications with ease.
Impact on Solana Programs
Solang's introduction as a Solidity compiler for Solana enhances the development process and encourages experienced Solidity developers to explore opportunities offered by the Solana blockchain.
Regarding its impact on Solana programs, Solang does not introduce any significant changes. The compilation process involves translating high-level Solidity source code into a lower-level representation that can be executed on the Solana blockchain. This allows interoperability between developers using different languages to write their programs and communicate on Solana.
At a high level, Solang supports:
- The Solana Library (SPL-Token and System Instructions)
- Builtin Imports
Solana Library
The Solana library is broken down into 2 different libraries within the Solang Github Repository:
- SPL-Token
- System Instructions
1. SPL-Token
With SPL support, you can create, mint, burn, and transfer SPL tokens using the Solang Spl-Token library. This gives you a suite of tools to manage SPL tokens from your Solang program.
To use it with your solidity code, you can start by copying the spl_token.sol file into your source tree.
2. System Instructions
With system instructions, it allows developers to utilize regular functions such as creating accounts, transferring, allocating account data, and paying transaction fees.
You can begin by using the same method we used for the SPL library and copy over the system_instruction.sol file into your source tree to begin using in your solidity code.
Builtin Imports
Builtin imports are available specifically for the Solana platform.
These allow you to utilize Solana program features such as:
- AccountInfo
- AccountMeta
- Program Derived Address (PDAs)
1. AccountInfo
AccountInfo gathers information about all accounts passed into a transaction. You can find out more here.
2. AccountMeta
When making a cross-program invocation (CPI) call, you can use Account Meta to specify the accounts that should be passed in.
3. PDAs
PDAs enable programmatically creating and using signatures when making calls between programs.
With Solang, you can create and retrieve PDAs created by a program address from the contract created, which will enhance the security of your application.
You can find additional builtins available on Solang here.
Get Started
You can get started on learning Solang through Solana docs here. This will guide you through an Anchor program build where you can create your first Solidity/Solana program using the Solang compiler.
This guide will help you navigate the initial learning curve, understanding the differences between smart contracts on Ethereum and Solana programs, particularly in how they handle state data. This is by far the largest hurdle in moving from Ethereum to Solana development.
Conclusion
In conclusion, Solang serves as a significant advancement for Ethereum Solidity developers looking to transition to Solana. By acting as a Solidity compiler for Solana, Solang reduces the learning curve associated with developing on the platform, enabling experienced Solidity developers to leverage their existing skills and knowledge. This compiler bridges the gap that previously existed, attracting developers who would have otherwise been hesitant due to the requirement of learning Rust or another language to create Solana programs.