# Stellar Operations, Balances, and Account Objects

### Operations

Operations are currently indexed by public key:

* all operations can be queried through the standard format `opnameByPublicKey`. For example, `paymentsByPublicKey`.
* operations that affect other accounts can also be queried `opnameToPublicKey`. For example, `paymentsToPublicKey`.

{% hint style="info" %}
We advise playing with the GraphiQL endpoint to craft the queries that best fit your requirements.
{% endhint %}

For example, to index payments from an account:

```graphql
query MyQuery {
  paymentsByPublicKey(publicKeyText: "PUBLIC_KEY") {
    nodes {
      accountByDestination {
        publickey
      }
      amount
      accountBySource {
        publickey
      }
      assetByAsset {
        code
        issuer
      }
      assetNative
      opId
      txInfoByTx {
        fee
        ledgerByLedger {
          closeTime
          sequence
        }
        txHash
        opCount
        memo
      }
      muxedaccountByDestinationMuxed {
        publickey
        id
      }
      muxedaccountBySourceMuxed {
        id
        publickey
      }
    }
  }
}
```

Note that source, destination, asset, and t-x info are references to other tables, and this is a standard way of retrieving the public keys. In general:

* If `assetNative` is `false`, then `assetByAsset` enables you to read the code and the issuer.
* If `muxedaccountByDestinationMuxed` is null, then `accountByDestination` holds the public key. And vice-versa for the operation source.

### Balances

To query balances for an account:

```graphql
query MyQuery {
  balanceByPublicKey(publicKeyText: "PUBLIC_KEY") {
    nodes {
      limit
      lpShare
      poolshareassetByLpShare {
        poolId
      }
      balance
      accountByAccount {
        publickey
      }
      assetByAsset {
        issuer
        code
      }
    }
  }
}
```

Note that if `lpShare` is `true`, then the balance is for the liquidity pool share of the pool `poolID`. Else, the asset is `assetByAsset`.

### Account Objects

To query the account object for an account:

```graphql
query MyQuery {
  accountObjectByPublicKey(publicKeyText: "PUBLIC_KEY") {
    nodes {
      accountByAccount {
        publickey
      }
      nativeBalance
      numSubEntries
    }
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mercurydata.app/mercury-classic/queries/stellar-operations-balances-and-account-objects.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
