LogoLogo
1.4.x
1.4.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
      • Resolving CSPR.name
    • 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.name resolution
      • Get CSPR.name resolution
    • 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
Export as PDF
  1. Documentation
  2. Highlights

Receiving contract-level events

PreviousDe-anonymizing account pursesNextResolving CSPR.name

Last updated 3 months ago

Web3 comes with a new storage architecture dApps have to embrace. In traditional Web2 applications, users don't interact with the storage directly. It's typically hidden behind the API layer.

Blockchain is data storage that provides data we can trust, and that trust requires no middleman between the users and the changes in the data. In this setup, dApps have to observe the on-chain activity to display the relevant state to the end users. While this can be done by polling the network state using the or , CSPR.cloud is also prepared to assist dApps developers with observing the on-chain activity with its .

curl -X 'GET' \
  'https://api.testnet.cspr.cloud/contracts?deploy_hash=149710648b6295b426fa31bb4b79b65374edd3e9ccd242b7d1bf6a7abb308f47' \
  -H 'accept: application/json' \
  -H 'authorization: 55f79117-fc4d-4d60-9956-65423f39a06a'
{
  "data": [
    {
      "contract_hash": "98f4b9ad7891d982e1b5f39e51dd332cae6f83f9615f3025af32796587bea527",
      "contract_package_hash": "19e6954b07d1b4d0341a6f73689c7fbc96959c33f4465c0e11c49b6bc850884a",
      "contract_type_id": 7,
      "contract_version": 1,
      "deploy_hash": "149710648b6295b426fa31bb4b79b65374edd3e9ccd242b7d1bf6a7abb308f47",
      "is_disabled": false,
      "timestamp": "2024-01-09T14:29:30Z"
    }
  ],
  "item_count": 1,
  "page_count": 1
}
wscat -c 'wss://streaming.testnet.cspr.cloud/contract-events?contract_hash=98f4b9ad7891d982e1b5f39e51dd332cae6f83f9615f3025af32796587bea527' \
  -H 'authorization: 55f79117-fc4d-4d60-9956-65423f39a06a'
{
  "data": {
    "contract_package_hash": "19e6954b07d1b4d0341a6f73689c7fbc96959c33f4465c0e11c49b6bc850884a",
    "contract_hash": "98f4b9ad7891d982e1b5f39e51dd332cae6f83f9615f3025af32796587bea527",
    "data": {
      "data": "{\"name\":\"User storage interaction in Web2\",\"description\":\"Users typically don\\u0027t interact directly with the data storage in Web2\",\"asset\":\"https://maritime.sealstorage.io/ipfs/bafybeicfojnysuueowj4mcparaxzkl5ckytq7ma5mqhhzju35r734ercra\"}",
      "recipient": "account-hash-1856e4a0b23c70b64e4509987680de0d99145fa0cdc71ad9b78760e18ff0deec",
      "token_id": "0"
    },
    "name": "Mint"
  },
  "action": "emitted",
  "extra": {
    "deploy_hash": "7d23a8b0cd927a7e54b6e55b267c8000016c3d0b3a9e97a2c281239c8a8f9120",
    "event_id": 0,
    "transform_id": 31
  },
  "timestamp": "2024-01-09T17:06:51.43910404Z"
}

Note the extra property that provides technical information, such as deploy_hash, event_id, and the deploy execution transform_id, which can be used to link the event data to the corresponding deploy properly.

To demonstrate it in action, let's create an NFT contract using the Testnet version of and observe its activity on the network. Navigate to the page and create a new collection. To listen to the contract-level events emitted by our contract, we'll need to know its hash. Copy the hash of the deploy that created your NFT collection on the last step of the collection creation process and query the contract it deployed to the network using the :

Knowing the contract hash, we can subscribe to the contract-level events emitted by our newly created contract using the . For this example, you'll need to install the utility.

Now, let's go back to and mint an NFT. Once the mint deploy is executed on the network, our WebSocket connection will receive a message containing the Mint event data, as well as the token data encoded as a JSON string:

CSPR.studio
My NFT collections
Contract REST API
Contract-level events Streaming API
wscat
NPM
CSPR.studio
CSPR.cloud REST API
CSPR.cloud Casper Node
Streaming API