Skip to content

Commit

Permalink
Contract Debugging (#284)
Browse files Browse the repository at this point in the history
* [skip ci]
  • Loading branch information
shramee committed Dec 28, 2022
1 parent 67cb028 commit bad6dec
Showing 1 changed file with 39 additions and 1 deletion.
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,
```
Adding balance...
0
25
```
If you want to have your debug lines printed in the same terminal as your hardhat script/test, use `integrated-devnet` with `stdout` set to `"STDOUT"` as documented in [runtime network](#runtime-network---integrated-devnet) section.
## Configure the plugin
Specify custom configuration by editing your project's `hardhat.config.ts` (or `hardhat.config.js`).
Expand Down

0 comments on commit bad6dec

Please sign in to comment.