Nomic Foundation
Published in

Nomic Foundation

Better Solidity debugging: console.log is finally here

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

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! 👷‍♀️👷‍♂️

--

--

--

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

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
Patricio Palladino

Patricio Palladino

Co-founder & CTO of Nomic Foundation

More from Medium

Writing your first Solidity Smart Contract with Remix IDE

Preventing Smart Contract Attacks on Ethereum — A Code Analysis

ABI encode and decode using solidity

Hosting a Decentralized Application for Free with GitHub Pages