# Receiving contract-level events

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.

![](https://3047213988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOT64KtA0pYITXdXhFxp2%2Fuploads%2Fgit-blob-8f3029d6535121aae9050901ec57f8618ce1e590%2Fuser-storage-interaction-in-web2.png?alt=media)

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 [CSPR.cloud REST API](https://docs.cspr.cloud/1.0.x/rest-api/reference) or [CSPR.cloud Casper Node](https://docs.cspr.cloud/1.0.x/casper-node-api/connecting-with-an-sdk), CSPR.cloud is also prepared to assist dApps developers with observing the on-chain activity with its [Streaming API](https://docs.cspr.cloud/1.0.x/streaming-api/reference).

![](https://3047213988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOT64KtA0pYITXdXhFxp2%2Fuploads%2Fgit-blob-3ac2c8bc02bc457ccbba23770ba5147fab6244c7%2Fuser-storage-interaction-in-web3.png?alt=media)

To demonstrate it in action, let's create an NFT contract using the Testnet version of [CSPR.studio](https://testnet.cspr.studio) and observe its activity on the network. Navigate to the [My NFT collections](https://testnet.cspr.studio/collections) 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 [Contract REST API](https://docs.cspr.cloud/1.0.x/rest-api/contract):

```bash
curl -X 'GET' \
  'https://api.testnet.cspr.cloud/contracts?deploy_hash=149710648b6295b426fa31bb4b79b65374edd3e9ccd242b7d1bf6a7abb308f47' \
  -H 'accept: application/json' \
  -H 'authorization: 55f79117-fc4d-4d60-9956-65423f39a06a'
```

```json
{
  "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
}
```

Knowing the contract hash, we can subscribe to the contract-level events emitted by our newly created contract using the [Contract-level events Streaming API](https://docs.cspr.cloud/1.0.x/streaming-api/contract-level-events). For this example, you'll need to install the [`wscat`](https://github.com/websockets/wscat) [NPM](https://www.npmjs.com) utility.

```bash
wscat -c 'wss://streaming.testnet.cspr.cloud/contract-events?contract_hash=98f4b9ad7891d982e1b5f39e51dd332cae6f83f9615f3025af32796587bea527' \
  -H 'authorization: 55f79117-fc4d-4d60-9956-65423f39a06a'
```

Now, let's go back to [CSPR.studio](https://testnet.cspr.studio) 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:

```json
{
  "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.
