Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#200 Debugging contracts #284

Merged
merged 5 commits into from
Dec 28, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion www/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ If you've used Hardhat 👷‍♀️👷‍♂️ and want to develop for StarkN
- [Install](#install)
- [CLI commands](#cli-commands)
- [API](#api)
- [Testing](#test)
- [Testing](#testing)
- [Important notes](#important-notes)
- [Examples](#test-examples)
- [Devnet examples](#devnet-examples)
- [Debugging contracts](#debugging-contracts)
- [Configure the plugin](#configure-the-plugin)
- [Account support](#account)
- [More examples](#more-examples)
Expand Down Expand Up @@ -375,6 +376,43 @@ Devnet offers [empty block creation](https://shard-labs.github.io/starknet-devne
const emptyBlock = await starknet.devnet.createBlock();
```

## Debugging contracts

To debug StarkNet contracts, you can use `print()` in cairo hints in your contract, and the printed lines will appear in Devnet's log.

Compile with `--disable-hint-validation` flag to allow hints.

```
hardhat starknet-compile --disable-hint-validation
```

For example, when calling the following `increase_balance` with input `25`.

```cairo
@external
func increase_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
amount: felt
) {
let (res) = balance.read();
%{ print( "Adding balance..." ) %}
%{ print( ids.res ) %}
balance.write(res + amount);
let (afterUpdate) = balance.read();
%{ print( ids.afterUpdate ) %}
return ();
}
```

DevNet logs look like this,
shramee marked this conversation as resolved.
Show resolved Hide resolved

```
Adding balance...
0
25
```

When using `integrated-devnet` you can specify `stdout` as `STDOUT` or a file in your hardhat config file. Documented in [runtime network](#runtime-network---integrated-devnet) section.
shramee marked this conversation as resolved.
Show resolved Hide resolved

## Configure the plugin

Specify custom configuration by editing your project's `hardhat.config.ts` (or `hardhat.config.js`).
Expand Down