Emitting events

Emitting events from go-plugins

The zeknd SDK gives a facility for the contracts to emit events that can be used for multiple purposes such as indexing. Currently, the zeknd SDK supports emitting events into a Redis sorted set.

#Configuring the zeknd SDK

By default, the zeknd SDK will only emit events to the log. To configure it to send the events to a Redis sorted set, add the following line to the zeknd.yaml config file:

EventDispatcherURI: "redis://localhost:6379"

This will start emitting events to the Redis server in a sorted set called zekndevents. Each event is added to the sorted set, with the score being the blockchain height.

#Emitting events

The code snippet below shows how to emit events from the contract:

    emitMsg := struct {
        Owner  string
        Method string
        Addr   []byte
    }{owner, "createacct", addr}
    emitMsgJSON, err := json.Marshal(emitMsg)
    if err != nil {
        log.Println("Error marshalling emit message")
    }
    ctx.Emit(emitMsgJSON)

#Subscribing to events

See this page for more information on subscribing to events

Last updated