Better Solidity debugging: console.log is finally here

A local Ethereum network designed for development: stack traces and console.log

Patricio Palladino
Jan 24, 2020 · 3 min read
Image for post
Image for post

It’s happening. Building smart contracts on Ethereum is slowly distancing itself from being a task better suited for Elon Musk’s friends on Mars, and looking more and more like something maybe doable by human beings.

Back in October, we launched Buidler EVM: a ganache-cli alternative that includes a fully featured Solidity-aware stack traces implementation. This was a big step towards a better developer experience, and now we’re releasing another highly anticipated Buidler EVM feature: console.log for Solidity.

Image for post
Image for post
Solidity debugging after Buidler EVM

Buidler EVM is a local Ethereum network designed for development. It allows you to deploy your contracts, run your tests and debug your code — and it was architectured as a platform to enable advanced tooling.

The main technique currently in use for logging data from Solidity is emitting events, but this approach is significantly limited: it only works on successful transactions. This is because the EVM doesn’t emit events when a transaction fails and given that when a transaction is going south is when developers need to understand what’s going on the most, this is tragic.

Buidler EVM carries a robust infrastructure for execution inspection that allowed us to implement a reliable console.log that’s always available, even when a transaction fails — and in true Buidler-fashion, it works with the testing tools of your choosing.

Using it is straightforward. Just import the console.sol file that contains the console.log function, and use it as you would in JavaScript.

Then run your tests using Buidler and Buidler EVM as the development network.

The contracts will compile with any tool, not just Buidler, so it’s safe to leave the logging calls in if that’s useful. Tools like Tenderly will integrate the scrapping of logs, so you can even deploy the logging code to testnets and mainnet if you wish. The calls into console.log don’t do anything when running in other networks, but they do incur a gas cost.

This latest release of Buidler EVM also adds support for Solidity 6 and the evm_snapshot and evm_revert JSON-RPC methods, allowing projects using snapshots to migrate to Buidler and keep their testing optimizations.

In combination with the stack traces feature, this release marks a new chapter in smart contract development productivity 🥳.

Take Buidler EVM’s console.log out for a spin!

mkdir console/
cd console/
npm init -y
npm install --save-dev @nomiclabs/buidler
npx buidler # and create a sample project
npx buidler test

Check Buidler out and forget your Solidity debugging frustrations today! 👷‍♀️👷‍♂️

Nomic Labs

We build open source software to unlock developer productivity in the Ethereum ecosystem.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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