Solidity Code Formatter
Format and beautify Solidity smart-contract source: re-indent by brace depth, normalize spacing around operators and punctuation, reorder function visibility/mutability modifiers, sort the pragma/import header, and normalize NatSpec comments — all in your browser.
Input
Style Options
Used when normalizing or inserting a missing pragma.
Long argument lists are wrapped to fit within this width.
Output
Guides
The Solidity Code Formatter cleans up and beautifies Solidity smart-contract source code. Paste a messy contract — inconsistent indentation, missing spaces around operators, cramped contract Foo{...} bodies — and get back tidy, readable code that follows the Solidity style guide, right in your browser.
What it does
The formatter tokenizes your Solidity source and re-emits it with consistent structure:
- Re-indents by nesting depth. Contract, library, interface, function, modifier and control blocks are indented one level per
{,(or[, so nested logic lines up cleanly. - Normalizes spacing. It puts single spaces around binary operators (
=,+,=>,>=), removes spaces before;,,and closing brackets, keeps member access (msg.sender) tight, and spaces control keywords (if (…),for (…)) apart from function calls (transfer(…)). - Reorders function modifiers. Visibility, mutability and inheritance keywords are sorted into the canonical
public → external → internal → private → pure → view → payable → virtual → overrideorder, with any custom modifiers kept afterward. - Organizes the header. With one option enabled,
pragmadirectives come first, thenimportstatements sorted alphabetically by path. - Manages the pragma version. Keep your existing
pragma solidityline, or normalize it to a version you choose — inserting one near the top if the file has none. - Normalizes NatSpec comments.
///doc comments and/** … */blocks get a single, consistent space after their markers. - Collapses blank lines and wraps long argument lists to your chosen column limit.
How to use it
- Paste your Solidity code into the input box, or upload a
.solfile. - Choose your indentation (4 spaces, 2 spaces, or tabs), brace style (K&R same-line or Allman next-line), and column limit.
- Toggle the reorder, sort, NatSpec and blank-line options to taste.
- The formatted result appears instantly — copy it or download it as
formatted.sol.
Is it a full compiler-grade formatter?
No — and that is by design. This is a fast, heuristic formatter that works purely on the token stream, not a full Solidity parser or the forge fmt / prettier-plugin-solidity toolchain. That keeps it instant and completely private (nothing is uploaded), and it handles the overwhelming majority of everyday contracts. For unusual constructs, review the output before committing.
Does my code leave my browser?
No. Formatting runs entirely on your device — your contract source is never sent to a server, which matters when the code may be unpublished or sensitive.
Which Solidity versions are supported?
The formatter is version-agnostic: it recognizes the full set of Solidity keywords and operators, so modern ^0.8.x contracts and older code format the same way.
Use it from code
From 3 credits per callREST API
curl -X POST https://api.iotools.cloud/v1/tool/solidity-code-formatter \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"solidityInput": "// SPDX-License-Identifier: MIT\npragma solidity …",
"solidityVersion": "keep",
"indentStyle": "4",
"braceStyle": "attach",
"printWidth": "120",
"sortModifiers": "true",
"sortPragmasImports": "true",
"normalizeNatspec": "true",
"collapseBlankLines": "true"
}'Swap in your own key from your account. The tool's fields are the body — no wrapper.
Ask an AI agent
Use the IOTools `solidity-code-formatter` tool (Solidity Code Formatter) on this input:
YOUR_INPUT_HEREPaste this at any agent connected to the IOTools MCP server, then add your input.