Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

docs: explain the diagnostic events that are emitted in sandbox #593

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions docs/getting-started/hello-world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -352,23 +352,72 @@ soroban contract invoke \
--to friend
```

The following output should appear.
The contract invocation should result in the following output.

```json
["Hello", "friend"]
```

:::info The `--` double-dash is required!

This is a general [CLI pattern](https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean) used by other commands like [cargo run](https://doc.rust-lang.org/cargo/commands/cargo-run.html). Everything after the `--`, sometimes called [slop](https://github.com/clap-rs/clap/issues/971), is passed to a child process. In this case, `soroban contract invoke` builds an _implicit CLI_ on-the-fly for the `hello` method in your contract. It can do this because Soroban SDK embeds your contract's schema / interface types right in the `.wasm` file that gets deployed on-chain. You can also try:

soroban contract invoke ... -- --help
```bash
soroban contract invoke ... -- --help
```

and

soroban contract invoke ... -- hello --help
```bash
soroban contract invoke ... -- hello --help
```

:::

### Diagnostic Events

You will also notice here (and with any other contract run in the sandbox environment) that some diagnostic output will be displayed on the screen. This is because the `soroban-cli` automatically sets the diagnostic level to "Debug" for contracts running in the sandbox.

Here, we'll see two diagnostic events were emitted by our contract invocation:

1. First is a `fn_call` diagnostic event. It tells you the _kind_ of event, the contract ID that will be called, the name of the function being called, and a vector of the arguments passed to the function. A (greatly simplified) version of this event's body would look like this:

```
{
event: {
body: {
topics: [
Symbol(fn_call),
Bytes(0000000000000000000000000000000000000000000000000000000000000001),
Symbol(hello),
],
data: Symbol(friend),
}
}
}
```

2. Next is a `fn_return` diagnostic event. These events are emitted when a contract call completes and contains the _kind_ of event, the name of the function that is returning, and the value returned by the function. A (greatly simplified) version of this event's body would look like this:

```
{
event: {
body: {
topics: [
Symbol(fn_return),
Symbol(hello),
],
data: [
Symbol(Hello),
Symbol(friend),
]
}
}
}
```

You can learn more about diagnostic events in our [Events article](../fundamentals-and-concepts/events#what-are-diagnosticevents).

## Optimizing Builds

Use `soroban contract optimize` to further minimize the size of the `.wasm`. First, re-install soroban-cli with the `opt` feature:
Expand Down