# 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
    }
  }
}
```
