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

# Generate ledger key parameters with a symbol key

> Generate ledger key parameters with a symbol key using the Stellar SDKs

A contract that keeps a value in persistent storage under the symbol `COUNTER` stores it in its own ledger entry. The snippets below build the ledger key for that entry. Pass the result in the `keys` array of [`getLedgerEntries`](https://developers.stellar.org/docs/data/apis/rpc/api-reference/methods/getLedgerEntries).

> [!NOTE]
>
> The [`increment` example contract](https://developers.stellar.org/docs/build/smart-contracts/getting-started/storing-data) keeps `COUNTER` in instance storage. Instance data is not a separate ledger entry. It lives in the contract instance entry, which [Retrieve a contract code ledger entry](https://developers.stellar.org/docs/build/guides/rpc/retrieve-contract-code.md) shows how to look up.

```js JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { Address, xdr } from "@stellar/stellar-sdk";

function getLedgerKeySymbol(contractId, symbolText) {
  const ledgerKey = xdr.LedgerKey.contractData(
    new xdr.LedgerKeyContractData({
      contract: new Address(contractId).toScAddress(),
      key: xdr.ScVal.scvSymbol(symbolText),
      durability: xdr.ContractDataDurability.persistent,
    }),
  );
  return ledgerKey.toXdr("base64");
}

console.log(
  getLedgerKeySymbol(
    "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI",
    "COUNTER",
  ),
);
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from stellar_sdk import xdr, scval, Address

def get_ledger_key_symbol(contract_id: str, symbol_text: str) -> str:
    ledger_key = xdr.LedgerKey(
        type=xdr.LedgerEntryType.CONTRACT_DATA,
        contract_data=xdr.LedgerKeyContractData(
            contract=Address(contract_id).to_xdr_sc_address(),
            key=scval.to_symbol(symbol_text),
            durability=xdr.ContractDataDurability.PERSISTENT
        ),
    )
    return ledger_key.to_xdr()

print(
    get_ledger_key_symbol(
        "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI",
        "COUNTER"
    )
)
```
