ℹ️ 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.
.png)
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.
.png)
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".
.png)
Successful uploading will generate a compilation with ID.
.png)
Continue with "Open Simulator", all parameters especially the source override will be configured correctly.
.png)
Once simulation is done, the console log will be put in the top section.
.png)
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.
.png)
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.
.png)
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.
- import
sentio/console.sol
.png)
- Add logs wherever you want
.png)
- 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.
.png)
- Upload your compilation to Sentio
.png)
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.
.png)
Updated 7 days ago