Turn Ethereum Addresses into Etherscan Links in iTerm2

When I write code that works with the Ethereum blockchain, I find myself copy-pasting hex addresses into the etherscan.io search box every five seconds. I was able to speed this up by adding a custom search engine for etherscan to chrome, but I still had to copy paste every address from my terminal into the browser.

Enter iTerm2 Triggers. They let you perform an action when text in your terminal matches a provided regular expression. Our goal is to turn every properly formatted hex address into a hyperlink to the etherscan.io search url.

First, following the instructions on the triggers page, create a new trigger in iTerm2 by opening Preferences > Profiles > Advanced:

In the top “Triggers” section click the “Edit” button to pop up the Triggers menu. Click the “+” button in the bottom left of the pop-up menu to create the new trigger. We want to match all Ethereum addresses and transactions, so set the Regular Expression to match a sequence of characters starting with “0x” and ending with between 40 (the length of an address) and 64 (the length of a transaction) hex characters (0–9, a-f, A-F). This expression should do the trick:

Next, set the Action to “Make Hyperlink…”

Finally, set the parameters to the Etherscan query URL, with the query value set to the value matched by our Regular Expression:

The final result should look like this:

Note that I widened out the “Parameters” column to fit the whole URL.

Click the “Close” button and exit out of the Preferences pane, then run this echo command in your terminal:

You should see the addresses have a bit more flair:

And if you cmd + click on them, they’ll take you straight to the correct Etherscan page:

Thanks for reading!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store