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

# What happens onchain and offchain

> Which SQD Network records are onchain and which work happens offchain.

SQD Network uses smart contracts for registration and token accounting. It uses
offchain services for storing blocks, scheduling copies, transporting queries, and
returning results.

| Onchain on Arbitrum                    | Offchain                                              |
| -------------------------------------- | ----------------------------------------------------- |
| Worker peer IDs and registration state | Blockchain block ingestion                            |
| Worker bonds                           | Chunk files in persistent storage and on worker disks |
| Delegation to workers                  | Scheduler calculations and assignment files           |
| Epoch and network parameters           | Peer discovery, heartbeats, and monitoring            |
| Portal or consumer allocations         | Queries and results between Portal and workers        |
| Approved reward accounting             | HTTP streams returned to clients                      |

## Identity connects the two sides

A worker or Portal generates a libp2p keypair. The public peer ID derived from that
key identifies the node on the peer-to-peer network. Registration or allocation
transactions associate that peer ID with an onchain account and locked SQD.

The private key stays with the node operator. It is used for peer identity and signed
network messages; it is not stored in a smart contract.

## Contracts coordinate participation

The current Network contracts include separate responsibilities:

* `WorkerRegistration` records worker peer IDs, bonds, registration epochs, and
  deregistration state.
* `NetworkController` stores parameters such as epoch length, worker bond amount,
  expected worker storage, target capacity, and reward limits.
* `Staking` records SQD delegated to each worker and accounts for each delegator's
  share of distributed rewards.
* allocation contracts account for the query capacity associated with SQD locked by
  data consumers or Portal operators.
* reward contracts accept approved reward batches and make worker and delegator
  rewards claimable.

These contracts do not decide which Parquet file answers a request. The assignment
and Portal make that routing decision offchain.

## Offchain services carry the data

Chunks can be much larger than an onchain transaction and queries need low-latency
streaming. The archive, scheduler, worker, and Portal services therefore operate
offchain:

1. ingestion writes finalized chunks to persistent storage;
2. the scheduler publishes a chunk-to-worker assignment;
3. workers download their assigned chunks;
4. Portal sends queries to workers over libp2p and returns the results over HTTP;
5. collectors record heartbeats and logs used for operations and analysis.

<CardGroup cols={2}>
  <Card title="Run a worker" icon="server" href="/en/network/worker">
    Follow the worker setup and registration procedure.
  </Card>

  <Card title="Delegate SQD" icon="link" href="/en/network/delegate">
    Follow the current delegation and withdrawal procedure.
  </Card>

  <Card title="Run Portal" icon="terminal" href="/en/portal/introduction/running-portal">
    Choose a hosted or self-hosted Portal path.
  </Card>

  <Card title="Network contracts" icon="database" href="https://github.com/subsquid/subsquid-network-contracts">
    Read the deployed addresses, contract responsibilities, and Solidity source.
  </Card>
</CardGroup>

## Implementation sources

* [Network contracts](https://github.com/subsquid/subsquid-network-contracts)
* [Contract client, peer identity, and transport](https://github.com/subsquid/sqd-network)
* [Worker node](https://github.com/subsquid/worker-rs)
* [Portal](https://github.com/subsquid/sqd-portal)


## Related topics

- [SQD Network components](/en/network/introduction/network-components.md)
- [SQD Network](/en/network/overview.md)
- [Pricing FAQ](/en/cloud/pricing/faq.md)
- [Reliability and monitoring](/en/network/introduction/reliability-and-monitoring.md)
- [Announcements](/announcements.md)
