Solang is a portable Solidity compiler for Solana and Substrate’s contracts pallet. I am excited to share some recent improvements made to Solang, focusing on enhancing the Solidity developer experience. This was a part of a grant I received from Web3Foundation.
Previously, when encountering an error block, Solang inserted an
unreachable instruction, which halted the execution without providing any indication of what went wrong. To address this, I implemented the following :
- Inserted a
- Linked the print instruction to the specific line in the Solidity code that generated the error. This allows developers to pinpoint the exact line of code causing the error. For instance, an overflow error would produce a message like this:
Addition overflow on line 35:12.
Additionally, I introduced a
release flag that disables all debugging options. Enabling this flag helps improve code size by removing debugging-related instructions.
Solang’s CLI has numerous options for configuring debugging, optimizations, and compiler output. Providing these options via the CLI was becoming cumbersome, so I added the option of reading the configurations from a toml file, similar to how Cargo.toml works. Here’s an overview of the changes:
- Developers can now create a
solang.tomlfile within their project directory.
solang compilecommand, when executed in a directory with a
solang.tomlfile, will automatically read the configurations from there.
To facilitate getting started with Solang, I added a new command,
solang new, which creates a new project. This command generates an example contract and an accompanying
solang.toml file. This way, developers can quickly set up their projects and have a template to work with.
To try out Solang on Polkadot’s parachains, follow these steps:
Install Solang by referring to the installation instructions available at Solang’s docs.
Run the command
solang new --target polkadot. This will create a new directory with an example contract and an example
Navigate to the project directory and execute
solang compile. This command will generate a
To interact with a Substrate contracts node, you can either set up a local Substrate contracts node or deploy the
.contractto a testnet.
Finally, install Substrate’s contracts UI and follow the necessary steps to upload the
flipper.contractfile. This will allow you to interact with the contract and see the results.
For more examples related to Polkadot integration, refer to Solang’s integration tests.
Please report any issues to Solang’s Github.