Most entry point functions return a type of
Response is a wrapper around Events in the Cosmos
Response type should be returned as the successful result of a contract entry point (i.e.
execute). You can declare it as mutable and add to it in the function body, but a more common pattern is to
construct it at the end and return it, if all computation has succeeded. In the examples that follow, it is wrapped
Ok as it is being returned as part of a function that is returning the
Result type, with
Right or success branch.
The exception to this is
query, which will return
StdResult<Binary> due to the Cosmos SDK interface.
The source for Response can help to understand it better .
The most simple usage of
Response is as follows:
This is common in instantiate functions, where no message is returned to the client.
However, in most
execute handling cases, a
Response should be returned:
let res = Response::new()
There's a bit more going on here, so let's unpack it. You can find the source here.
- A new
- Several key/value pairs are added
- This is returned wrapped in a
If you're calling your contract via the command-line interface (CLI) you will see them logged as part of the
response, alongside other SDK events.
Instead of just adding attributes,
.add_event can be used to add an unwrapped event.
These events can be interacted with by other clients or contracts.