LogoLogo
CSPR.build Portal
1.2.x
1.2.x
  • Documentation
    • Introduction
    • Overview
      • Authorization
      • Rate limits and quotas
      • Pagination
      • Sorting
      • Filtering
      • Optional properties
      • Errors
    • Getting started
    • Highlights
      • Including related entities
      • Including CSPR rates
      • Including account info
      • Accessing auction data
      • Accessing token data
      • Accessing NFT data
      • De-anonymizing account hashes
      • De-anonymizing account purses
      • Receiving contract-level events
    • Changelog
  • REST API
    • Reference
    • Account
      • Get account
      • Get accounts
    • Account Info
      • Get account info
      • Get account infos
    • Auction metrics
      • Get auction metrics
    • Awaiting deploy
      • Create Awaiting Deploy
      • Add Awaiting Deploy signatures
      • Get Awaiting Deploy
    • Block
      • Get block
      • Get blocks
      • Get validator blocks
    • Bidder
      • Get bidder
      • Get bidders
    • Centralized account info
      • Get centralized account info
      • Get centralized account infos
    • Contract
      • Get contract
      • Get contracts
      • Get contracts by contract package
      • Get contract types
    • Contract entry point
      • Get contract entry points
      • Get contract entry point costs
    • Contract package
      • Get contract package
      • Get contract packages
      • Get account contract packages
    • Delegation
      • Get account delegations
      • Get validator delegations
    • Delegator reward
      • Get account delegator rewards
      • Get total account delegation rewards
      • Get total validator delegators' rewards
    • Deploy
      • Get deploy
      • Get deploys
      • Get account deploys
      • Get block deploys
      • Get deploy execution types
    • Fungible token action
      • Get fungible token actions
      • Get fungible token action types
      • Get account fungible token actions
      • Get contract package fungible token actions
    • Fungible token ownership
      • Get account fungible token ownership
      • Get contract package fungible token ownership
    • Non-fungible token (NFT)
      • Get NFT
      • Get account NFTs
      • Get contract package NFTs
      • Get NFT standards
      • Get off-chain NFT metadata statuses
    • Non-fungible token (NFT) action
      • Get contract package NFT actions for a token
      • Get account NFT actions
      • Get contract package NFT actions
      • Get NFT action types
    • Non-fungible token (NFT) ownership
      • Get contract package NFT ownership
      • Get account NFT ownership
    • CSPR rate
      • Get the current currency rate
      • Get historical currency rates
      • Get currencies
    • CSPR supply
      • Get supply
    • Transfer
      • Get account transfers
      • Get deploy transfers
    • Validator
      • Get validator
      • Get validators
    • Validator performance
      • Get historical validator performance
      • Get historical average validator performance
      • Get historical average validators performance
    • Validator reward
      • Get validator rewards
      • Get validator total rewards
  • Streaming API
    • Reference
    • Account balance
    • Block
    • Contract
    • Contract package
    • Contract-level events
    • Deploy
    • Fungible token action
    • Non-fungible token (NFT)
    • Non-fungible token (NFT) action
    • Transfer
  • Casper Node API
    • Connecting with an SDK
Powered by GitBook
On this page
  • Properties
  • Optional properties
  • Endpoint
  • Query params
  • Events
  • Response
  • Example
  1. Streaming API

Contract-level events

PreviousContract packageNextDeploy

Last updated 10 months ago

The contract-level events stream provides the possibility to subscribe to events emitted by contracts during their execution. dApps rely on these events to know what happened during the contract execution to present this information to their users.

In addition to , CSPR.cloud also provides integration with the legacy map-based events implemented as maps containing the event information to the network store, which look like this:

 [
  {
    "key": "contract_package_hash",
    "value": "c4e5a03066ce3c6006f562939e48f7076c77de5d46cf8fe625c41e02c5e74814"
  },
  {
    "key": "event_type",
    "value": "cep47_mint_one"
  },
  {
    "key": "recipient",
    "value": "Key::Account(4e37642c85513d3eef943d4f8250dec1e8c741e88b166f0e363e985d61e2a0c4)"
  },
  {
    "key": "token_id",
    "value": "1242"
  }
]

Properties

The ContractLevelEvent entity has the following properties:

Property
Type
Description

contract_package_hash

string(64)

Contract package hash

contract_hash

string(64)

data

JSON

Event data in the JSON format. Complex types may lose information because the CLValue type is wider that JSON. Please, use raw_data in such a case

raw_data

string

Event data represented as a hexadecimal string, similarly as presented in the deploy transform

name

string

Event name

Optional properties

Property
Type
Description

raw_data

string

Raw event data encoded as a hexadecimal string

Example

{
  "contract_package_hash": "0c66ee5cfe1ab3e1e7cae31f6c60fef631e7a7ee409a144cd19eeaeee20f4284",
  "contract_hash": "0fc4ba4162de03cd03f00521bbb481afd3c64a345436e9ebd9c7835e9d8c566d",
  "data": {
    "recipient": "account-hash-1856e4a0b23c70b64e4509987680de0d99145fa0cdc71ad9b78760e18ff0deec",
    "token_id": "3"
  }
  "raw_data": "00f8221af2ee00c69edbab4a02f523d324ce7282c8fc809fe84622bdb6b3f314420500e40b5402",
  "name": "Mint"
}

Endpoint

GET /contract-events

Query params

Property
Type
Description

contract_hash

string

Comma-separated contract hashes

contract_package_hash

string

Comma-separated contract package hashes

Exactly one owner_hash or contract_package_hash filter must be provided

Events

Event
Description

emitted

Notifies about new contract event being emitted during a deploy execution

Response

Example

wscat -c 'wss://streaming.testnet.cspr.cloud/contract-events?contract_hash=0fc4ba4162de03cd03f00521bbb481afd3c64a345436e9ebd9c7835e9d8c566d,220cdd3ebf41503cad5dc094d0237d85fbd39bb585ce970e3d4c0ad9c6c1b413&includes=raw_data' \
  -H 'authorization: 55f79117-fc4d-4d60-9956-65423f39a06a'
{
  "data": {
    "contract_package_hash": "523bfb3faec58c37be5637c1911e8545aa62d257a8f38a315fddedab56cb4406",
    "contract_hash": "220cdd3ebf41503cad5dc094d0237d85fbd39bb585ce970e3d4c0ad9c6c1b413",
    "data": {
      "choice": 1,
      "stake": "1000000000",
      "voter": "account-hash-f8221af2ee00c69edbab4a02f523d324ce7282c8fc809fe84622bdb6b3f31442",
      "voting_id": 6,
      "voting_type": 0
    },
    "raw_data": "00f8221af2ee00c69edbab4a02f523d324ce7282c8fc809fe84622bdb6b3f314420600000000000000010000000400ca9a3b",
    "name": "BallotCast"
  },
  "action": "emitted",
  "extra": {
    "deploy_hash": "8655a223c004c44115296db030780100981cd6f7fe499d676c3f93543baaeef1",
    "event_id": 13,
    "transform_id": 125
  },
  "timestamp": "2023-12-15T12:16:11.041209483Z"
}

If you are a new developer, we recommend you to use CES when developing your smart contracts. It has become the de facto standard on the network and is already supported by the existing fungible and non-fungible (NFT) token standards, such as , , and .

Contract hash. Present only for events

To learn more, please proceed with an extended example described on the page.

Casper Event Standard (CES)
CEP-18
CEP-47
CEP-78
Receiving contract-level events
CES
<ContractLevelEvent>
WebSocketMessage