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 has the following features:
- Change solidity pragma version
functioncomplex parameters like arrays that lack an already defined storage location. Add
storagekeyword to public, private and internal complex parameters that don’t already have a defined parameter storage location.
- Rename constructor function definition
- Add default function visibility
tothose functions which don’t have function visibility explicitly defined.
- Add function visibility
tofallback functions and all functions of anyinterface. Convert
functionstate mutability modifier to
- Prettify your code using prettier.
Using this plugin is very straightforward and only requires two simple commands:Firstly, you need to install the npm plugin via
npm install --save-dev prettier prettier-plugin-solidity-refactorSecondly, you need to execute the plugin using
./node_modules/.bin/prettier --write --tab-width 4 --print-width 140 '**/*.sol'
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 🙂
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 :).