Better Solidity debugging: console.log is finally here

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

Patricio Palladino
Jan 24 · 3 min read

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.

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.

contract/Greeter.sol in Buidler’s sample project

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 design, build and audit decentralized systems.

Patricio Palladino

Written by

Nomic Labs co-founder. Voltaire member.

Nomic Labs

We design, build and audit decentralized systems.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade