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

Update errors example to use the latest cli. #768

Merged
merged 3 commits into from
Mar 12, 2024
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
46 changes: 32 additions & 14 deletions docs/tutorials/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -333,34 +333,52 @@ target/wasm32-unknown-unknown/release/soroban_errors_contract.wasm

## Run the Contract

If you have [`soroban-cli`] installed, you can invoke contract functions in the
Wasm using it.
Let's deploy the contract to Testnet so we can run it. The value provided as `--source` was set up in our Getting Started guide; please change accordingly if you created a different identity.

```sh
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/soroban_errors_contract.wasm \
--source alice \
--network testnet
```

The command above will output the contract id, which in our case is `CC3UMHVTIEH6GGDBW7MM72Q545HBDCXGU3GMIXP23PQVSBFKNZRWT37X`.

Now that we've deployed the contract, we can invoke it.

```sh
soroban contract invoke \
--wasm target/wasm32-unknown-unknown/release/soroban_errors_contract.wasm \
--id 1 \
--id CC3UMHVTIEH6GGDBW7MM72Q545HBDCXGU3GMIXP23PQVSBFKNZRWT37X \
--network testnet \
--source alice \
-- \
increment
```

Run the command a few times and on the 6th invocation the following output should occur.
Run the command a few times and on the 6th invocation you should see an error like this:

```
❯ soroban contract invoke \
--wasm target/wasm32-unknown-unknown/release/soroban_errors_contract.wasm \
--id 1 \
-- \
increment
error: HostError
Value: Status(ContractError(1))
...
error: transaction simulation failed: host invocation failed

Caused by:
HostError: Error(Contract, #1)

Event log (newest first):
0: [Diagnostic Event] contract:<your contract id>, topics:[error, Error(Contract, #1)], data:"escalating Ok(ScErrorType::Contract) frame-exit to Err"
1: [Diagnostic Event] topics:[fn_call, Bytes(b7461eb3410fe31861b7d8cfea1de74e118ae6a6ccc45dfadbe15904aa6e6369), increment], data:Void
...
```

Use the `soroban` to inspect what the counter is.
To retrieve the current counter value, use the command `soroban contract read`.

```sh
soroban contract read --id 1 --key COUNTER
soroban contract read \
--id CC3UMHVTIEH6GGDBW7MM72Q545HBDCXGU3GMIXP23PQVSBFKNZRWT37X \
--network testnet \
--source alice \
--durability persistent \
--output json
```

[`soroban-cli`]: ../getting-started/setup.mdx#install-the-soroban-cli
Loading