In my previous post, we looked at the web3j-unit and web3j-evm libraries. These are tools that help you test your Solidity smart contracts using Web3j and Java. In this blog post we’ll spend some more time looking at the console debugger you find in the web3j-evm library.

The console debugger, or ConsoleDebugTracer as it’s also called, allows you to step into the details of what’s going on when you deploy and interact with a smart contract. While initially we only supported showing you the low-level opcodes and the stack, we’ve been working on extending this to also include the Solidity source code. As of release 4.5.12, this is generally available.

Running the EVM example demo, with Solidity breakpoints

The above demo is showing many of the features of our debugger. Here’s how you’d do this locally from your terminal:



$ cd web3j-evmexample

$ ./gradlew --console=plain clean build run $ git clone https://github.com/web3j/web3j-evmexample.git $ cd web3j-evmexample$ ./gradlew --console=plain clean build run

When running gradlew you’re starting the main Demo class. Because the project is configured to use our solidity gradle plugin, it also takes care of compiling all the Solidity contracts. As the demo starts you’ll be brought in to the console debugger and we’ll set up a breakpoint:

: break Greeter.sol 13

With that added we can do the next command to skip through the first two transactions.

: next

: next

At this point, you will see “Greeter was deployed, about to get greeting..” on the console. We’re now entering the transaction that will fetch the greeting. The function that gives us this greeting happens to be located around line 13 in the Greeter.sol contract, where we added out breakpoint earlier. Doing next now will bring us there.

: next

At this point, you’ll notice a lot of low-level opcodes and some stack details. We hide these with the hide command.

: hide opcodes

: hide stack