Solidity 0.5.X is here with a lot of features and breaking changes. Making all the changes to your solidity code manually, especially adding the explicitness requirements can be really cumbersome (and boring) for large projects. This is why I decided to make a codemod for Solidity that does most of the work for you. It’s still under testing and is buggy but it gets the job done for the most part. You may see its magic in the underworks polymath-core repo branch.

The plugin is based on the solidity prettier plugin that extends the features of prettier, a well-known code formatter. It is available as an NPM package and the source code is hosted on GitHub.

Features

The plugin has the following features:

Change solidity pragma version to ^0.5.0 . Add calldata storage keyword to external function complex parameters like arrays that lack an already defined storage location. Add memory storage keyword to public, private and internal complex parameters that don’t already have a defined parameter storage location. Rename constructor function definition from function ContractName to constructor . Add default function visibility of public to those functions which don’t have function visibility explicitly defined. Add function visibility of external to fallback functions and all functions of any interface. Convert constant function state mutability modifier to view . Prettify your code using prettier.

Usage

Using this plugin is very straightforward and only requires two simple commands:

npm install --save-dev prettier prettier-plugin-solidity-refactor

./node_modules/.bin/prettier --write --tab-width 4 --print-width 140 '**/*.sol'

Firstly, you need to install the npm plugin viaSecondly, you need to execute the plugin using

More detailed usage instructions and information is available on the GitHub repo.

Feel free to play around with the plugin and let me know if you find any bug. Refactoring your solidity code should be less boring now 🙂

Disclaimer

Remember that this plugin is still in testing and lacks a few features. Nevertheless, it should save a decent chunk of time if you are planning on refactoring your code. Read more about its limitations and known bugs on GitHub and always manually verify all your code. I won’t be liable if your cat loses one of their live or the ethereum blockchain hangs due to the use of this plugin :).