Introducing Solang Improvements

Introducing Solang Improvements

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.

Milestone 1: Debugging Experience

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 :

  1. Inserted a print instruction (debug_message on Substrate) that displays the runtime error before the unreachable instruction is encountered.
  2. 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.

Milestone 2: Usability Improvements

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:

  1. Developers can now create a solang.toml file within their project directory.
  2. The solang compile command, when executed in a directory with a solang.toml file, 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.

Trying Solang on Polkadot parachains

To try out Solang on Polkadot’s parachains, follow these steps:

  1. Install Solang by referring to the installation instructions available at Solang’s docs.

  2. Run the command solang new --target polkadot. This will create a new directory with an example contract and an example solang.toml file.

  3. Navigate to the project directory and execute solang compile. This command will generate a flipper.contract file.

  4. To interact with a Substrate contracts node, you can either set up a local Substrate contracts node or deploy the .contract to a testnet.

  5. Finally, install Substrate’s contracts UI and follow the necessary steps to upload the flipper.contract file. This will allow you to interact with the contract and see the results.

  6. For more examples related to Polkadot integration, refer to Solang’s integration tests.

Please report any issues to Solang’s Github.

1 Like