Emacs Solidity Mode
A simple language mode for the Solidity language. It is a constant work in progress as the language itself also progresses. For information about Solidity check the Tutorial and the Features wiki pages.
You can simply load the file in your emacs but the recommended way to install it is either via el-get or MELPA.
If you don’t know how to use el-get you can find more information on its webpage. First install el-get and then (in emacs), press
Alt+x (this is in emacs notation written as
M-x ) and then type
el-get-install. This will prompt you for a package, type
solidity-mode and hit enter, this should install all you need.
By default solidity-mode associates itself with any files ending in
el-get then you should have a specific package initializing lisp file. If not then you can put these
anywhere in your
Regardless of where you installed solidity mode from, you need to require the package:
(append that line to your
You can also set the way the comments are inserted by emacs with commands like
comment-region. The default is
/* .. */ and you can turn it to using
// instead by putting the following into your emacs config:
(setq solidity-comment-style 'slash) ;; or (setq solidity-comment-style 'star) ;; this is the default
You can modify the default keybindings of the solidity mode keymap by adding a new key combination for each command you want to change. For example
(define-key map (kbd "C-c C-g") 'solidity-estimate-gas-at-point)
Interface with linters
Provide path to solc binary
solc binary is assumed to be part of the PATH. Wherever that is not the case you would have to manually
set the location of the binary like below:
(setq solidity-solc-path "/home/lefteris/ew/cpp-ethereum/build/solc/solc")
Note: This better be set before requiring solidity mode.
Provide path to solium binary
solium binary is assumed to be part of the user’s
PATH. If this is not the case
then set its location like below:
(setq solidity-solium-path "/home/lefteris/.npm-global/bin/solium")
[Optional] Flycheck interface
Solidity mode can also interface with flycheck if you have it. Make sure to download and install the flycheck package. Then configure it to either work on all modes or enable it only for solidity mode.
Flycheck can interface with solc and/or with solium. You have to specifically set the path to both executables and activate the checker integration by setting the following:
(setq solidity-flycheck-solc-checker-active t)
(setq solidity-flycheck-solium-checker-active t)
Keep in mind that you need to provide the path to either solc or solium unless
emacs can already find it in your environment’s
PATH. Even if you can call it
from the command line it does not mean that EMACS can see it as emacs may be started
by systemd at which point
PATH is not fully populated.
Configuring solc checker
You can configure flycheck’s solc invocation with the following arguments
By default this is false. If you want to include the standard contracts just add the following to your emacs init file
(setq flycheck-solidity-solc-addstd-contracts t)
Configuring solium checker
You can configure flycheck’s solium incocation with the following arguments
solium RC file
By default solium looks at the current directory of the file you are editing in order to find
.soliumrc.json. Having this
file is required. But you can point to an external configuration file by putting the following anywhere in your emacs init file.
(setq flycheck-solidity-solium-soliumrcfile "/home/path/to/common/.soliumrc.json")
Chaining both checkers
If you enable both checkers then their results are chained. The variable
how they are chained. Its value can be either
info and that controls the maximum error level
of the solc checker after which solium will not run. If
t is given solium will always run. The default is
if anything over than a warning is found in solc solium will not run.
company-solidity, a simple company-mode back-end for Solidity, has now been fully integrated into solidity-mode. You no longer need to install company-solidity separately from solidity-mode, nor should you do so. To take advantage of the autocompletion features, you must have the company-mode package installed. The autocompletion features will be enabled automatically if you have company-mode installed.
What it does
Give completion suggestions for Solidity keywords, global variables, and address methods.
What it isn’t
Smart. The completion suggestions are not context dependent.
Something to watch out for
. as the end of a word, and will cut off compeletion suggestions when you type a
.. So, when you’ve typed
msg you will get
msg.value etc. as completion suggestions. However, as soon as you type
msg., the suggestions will disappear.
If you want autocomplete suggestions to include local variables, in addition to Solidity keywords, add the following to your
(add-hook 'solidity-mode-hook (lambda () (set (make-local-variable 'company-backends) (append '((company-solidity company-capf company-dabbrev-code)) company-backends))))
Gas estimate of function under point
You can get an estimate of the function under the cursor, by placing the curson
on top of the function name and typing
This will call
solidity-estimate-gas-at-point and provide a max gas estimate,
if possible, for the function.
- Syntax highlighting
- On the fly syntax checking with flycheck
- Gas estimation for function under point