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

# Maintain a Feed

> Subscribe with USDC, derive a feed ID, then run a gateway round and submit the signed result on-chain.

Maintaining a feed requires an active subscription. Reading existing feeds requires no subscription.

## 1. Subscribe

```ts theme={null}
import { PlanType } from "@molpha/sdk";

const plan = await sdk.solana.getPlan(PlanType.Basic);

await sdk.solana.subscribe(PlanType.Basic, {
  maxPriceUsdc: plan.subscriptionPrice,
});

// Later: renew for another period
await sdk.solana.extendSubscription({
  maxPriceUsdc: plan.subscriptionPrice,
});
```

`maxPriceUsdc` is a safety bound: the transaction aborts if the on-chain price is higher than the user approved.

## 2. Derive `feedId`

Feed identity is deterministic. No separate creation transaction is sent.

```ts theme={null}
import { deriveApiConfigHash, deriveFeedIdString } from "@molpha/sdk";

const apiConfig = {
  url: "https://api.example.com/price",
  responseParser: "$.price",
};

const signaturesRequired = 3;
const feedId = deriveFeedIdString(
  wallet.publicKey.toBytes(),
  deriveApiConfigHash(apiConfig),
  signaturesRequired,
);
```

The first successful submit creates the Solana `Feed` account if it does not exist.

## 3. Request and submit

```ts theme={null}
const { result, signature } = await sdk.requestAndSubmit(feedId, {
  apiConfig,
  signaturesRequired,
});

const feed = await sdk.solana.readFeed(feedId);
console.log(feed?.value, feed?.canonicalTimestamp, signature);
```

`requestAndSubmit` is equivalent to:

```ts theme={null}
const result = await sdk.gateway.requestSignedData({
  feedId,
  apiConfig,
  signaturesRequired,
});

const { signature } = await sdk.solana.submitDataUpdate(result);
```

## Constraints

* Subscription must be active.
* Requested quorum must be within the subscription's signer limit.
* Delegates must be active when the consumer authority differs from the subscription owner.
* `feedId` must match the canonical API config hash and quorum.
* A submitted update must have a strictly newer `canonical_timestamp`.

## Fast repeated rounds

For repeated updates, cache registry selection config and nodes:

```ts theme={null}
const context = await sdk.gateway.prepareContext(feedId);

const result = await sdk.gateway.requestSignedData({
  feedId,
  apiConfig,
  signaturesRequired,
  context,
});
```

## Next steps

<CardGroup cols={2}>
  <Card title="Read and verify" icon="magnifying-glass" href="/guides/read-and-verify">
    Consume maintained feed accounts or verify fresh payloads.
  </Card>

  <Card title="Gateway API" icon="cloud" href="/protocol/gateway">
    HTTP route, request auth, x402, and settlement details.
  </Card>
</CardGroup>
