ℹ️ Dynamic Logging

Dynamic logging provides an easy way to inspect the state of transactions during execution with simulation. It allows developers to add logs like

console.log("%d", localVar);

into any on-chain contract and extract the information with simulation.

The following video shows the full workflow of how you can use it.

To do dynamic logging, there are multiple ways, either by #web-ui or #ide-and-command-line. If the contract is developed by yourself, also consider using the hardhat plugin to upload-compilation.

Web UI

Open a transaction's contract tab, e.g. here. Click the "Start Override" Button.

Then you will enter editing mode. At the top of the file, insert

import "sentio/console.sol"

to the import section of the file. And then you can do any console logging just as you can do with hardhat or foundry. As the following picture shows, once the editing is done, click "Submit & Simulate".

Successful uploading will generate a compilation with ID.

Continue with "Open Simulator", all parameters especially the source override will be configured correctly.

Once simulation is done, the console log will be put in the top section.

IDE & Command Line

You can also do this in your local VS Code if you need more advanced editing. First, download the contract as a zip file.

After extracting the zip file, you will get a file structure like this. It is recommended to use VS Code as the development environment, which has better linting support.

  • /src contains source code for the contract.
  • /metadata.json contains necessary information for compiling and uploading.
  • /compile.sh fetches solidity compilers and compiles on your local machine.
  • /upload.sh uploads modified source code to Sentio.

In the source folder, sentio/console.sol will be included alongside the original sources of the contract. It contains utilities for printing debug information in simulation and transaction replaying, just like console.log in JavaScript. Console outputs will be collected and displayed on the Sentio debugger.

  1. import sentio/console.sol
  1. Add logs wherever you want
  1. Try compiling on your local machine. Note that for old versions of solidity compilers, warnings may appear in the console. It won't affect actual compiling process.
  1. Upload your compilation to Sentio

If you haven't logged in with Sentio CLI before, you may need to login first following the instructions in the console.

Now you can go back to the original transaction page, open the simulator, and choose your compilation in the Source Override section to start simulation.