Watching contract activity over RPC
Focus: one typed fire_rpc_event payload that off-chain clients can watch through daemon WebSocket contract_event notifications.
rpc_notice.slx
struct RpcNotice {
message: string
}
entry notify(message: string) {
fire_rpc_event(90, RpcNotice { message })
return 0
}How it works
RpcNoticeis a dedicated RPC struct, so clients receive named fields instead of a positionalany[].notify(message)is the only contract entry in this example.fire_rpc_event(90, RpcNotice { message })produces a daemon WebSocketcontract_eventnotification.
Subscribe once to daemon RPC method subscribe with notify set to contract_event. The notification contains the contract hash, the event id 90, and the encoded RpcNotice data.
Useful event names for contract development:
contract_deploy: a contract was deployed.contract_invoke: a contract entry was invoked.contract_event: a contract calledfire_rpc_event.contract_transfers: a contract transferred assets.new_asset: a new asset was created.
Last updated on