This site requires Javascript to be enabled.

Debugging

Debugging is a crucial aspect of smart contract development, as it allows you to identify, diagnose, and resolve issues that may arise during the contract's execution. By mastering the debugging techniques presented here, you'll be better equipped to create secure, robust, and performant smart contracts.

In this section you can find tips for debugging Archway projects.

Debug the developer CLI

Sometimes the CLI panics inside of a Node.js thread and exits with a nondescript error message. You can trace the actual source of the error by setting DEBUG=*

Example:

DEBUG=* archway deploy --args '{ "name": "debugger", "symbol": "dbg!", "minter": "archway1f395p0gg67mmfd5zcqvpnp9cxnu0hg6r9hfczq" }'

Debug failing transactions

If your transaction is failing use the cargo schema command to regenerate the schema requirements for your project. The generated files will explain the exact keys, types, and values that are permissible for the entrypoints of the contract.

Example:

$ cargo schema    Finished dev [unoptimized + debuginfo] target(s) in 0.10s     Running `target/debug/examples/schema`Removing "/home/user/projects/increment-project/schema/state.json"Removing "/home/user/projects/increment-project/query_msg.json"Removing "/home/user/projects/increment-project/instantiate_msg.json"Removing "/home/user/projects/increment-project/count_response.json"Removing "/home/user/projects/increment-project/execute_msg.json"Created /home/user/projects/increment-project/instantiate_msg.jsonCreated /home/user/projects/increment-project/execute_msg.jsonCreated /home/user/projects/increment-project/query_msg.jsonCreated /home/user/projects/increment-project/state.jsonCreated /home/user/projects/increment-project/count_response.json

Now you can print the regenerated schema for instantiate_msg to see the type and format requirements for your specific instantiation.

Example:

$ cat schema/instantiate_msg.json{  "$schema": "http://json-schema.org/draft-07/schema#",  "title": "InstantiateMsg",  "type": "object",  "required": [    "count"  ],  "properties": {    "count": {      "type": "integer",      "format": "int32"    }  }}

The above schema tells us that we need to send arguments to the deployer in the format --args '{"count":0}'. For example, sending them as --args '{"count":"0"}' will result in a failure.

Debugging with RUST_LOG

When working with Rust projects, you can use the RUST_LOG environment variable to control the logging output. This can be particularly helpful in debugging complex issues. For instance, you can set RUST_LOG to different log levels like info, debug, or trace to get more detailed logs:

RUST_LOG=debug cargo test

This command will show more detailed logs while running tests, which can help you identify issues within your smart contract code.