> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sequence.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Subscriptions

> 任意のウォレットやコントラクトアドレスのイベント、レシート、残高更新を購読できます。

## Subscribe to Blockchain Events

サブスクリプションエンドポイントを使って、さまざまなブロックチェーンイベントをリアルタイムで購読できます。フィルターを利用して、特定のコントラクトアドレスやアカウントアドレス、トークンIDなどを監視できます。

### Subscribing to Events

*Sequence Indexer `SubscribeEvents` Method:*

* Request: `POST /rpc/Indexer/SubscribeEvents`
* Content-Type: `application/json`
* ボディ（JSON形式）：
  * `Filters` (\[]object) -- an array of filters
    * `contractAddresses` (\[]string) -- a ERC20 / ERC721 / ERC1155 contract address
    * `accounts` (\[]string) -- wallet addresses
    * `tokenIDs` (\[]int) *optional* -- an array of token ids
    * `events` (\[]string) -- an array of event names
    * `topicHashes` (\[]string) -- an array of topic hashes

One of `contractAddresses`, `accounts` must be provided in the filter.

### Subscribing to Balance Updates

*Sequence Indexer `SubscribeBalanceUpdates` Method:*

### Subscribing to Receipts

*Sequence Indexer `SubscribeBalanceUpdates` Method:*

Example `SubscribeEvents`

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    -H 'Content-type: application/json' \
    -H "X-Access-Key: c3bgcU3LkFR9Bp9jFssLenPAAAAAAAAAA" \
    https://polygon-indexer.sequence.app/rpc/Indexer/SubscribeBalanceUpdates \
    -d '{"contractAddress":"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"}'
  ```

  ```go Go theme={null}
  import (
    "context"
    "log"

    "github.com/0xsequence/go-sequence/indexer"
    "github.com/0xsequence/go-sequence/lib/prototyp"
  )

  func SubscribeEvents() {
    seqIndexer := indexer.NewIndexer("https://polygon-indexer.sequence.app", "c3bgcU3LkFR9Bp9jFssLenPAAAAAAAAAA")

    reader, err := seqIndexer.SubscribeEvents(
      context.Background(),
      &indexer.EventFilter{
        ContractAddresses: []prototyp.Hash{prototyp.HashFromString("0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359")},
      },
    )
    if err != nil {
      log.Fatalf("SubscribeEvents: %v", err)
    }

    for {
      event, err := reader.Read()
      if err != nil {
        log.Fatalf("Read: %v", err)
      }

      log.Println("Event", event)
    }
  }
  ```

  ```typescript [TypeScript] theme={null}
  // Works in both a Webapp (browser) or Node.js:
  import { SequenceIndexer, WebrpcError } from '@0xsequence/indexer'

  const indexer = new SequenceIndexer('https://polygon-indexer.sequence.app', 'c3bgcU3LkFR9Bp9jFssLenPAAAAAAAAAA')

  const req = {
      filter: {
        contractAddresses: ['0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'],
      },
  }

  const options = {
    onMessage: (msg: any) => {
      console.log('msg', msg)
    },
    onError: (err: WebrpcError) => {
      console.error('err', err)
    }
  }

  await indexer.subscribeEvents(req, options)
  ```
</CodeGroup>
