Generate ledger key parameters with a symbol key using the Python SDK
In the increment
example contract stores an integer value in a ledger entry that is identified by a key with the symbol COUNTER
. The value of this ledger key can be derived using the following code snippets.
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"
)
)
Guides in this category:
📄️ Generate ledger key parameters with a symbol key using the Python SDK
Generate ledger key parameters with a symbol key using the Python SDK
📄️ Retrieve a contract code ledger entry using the JavaScript SDK
Retrieve a contract code ledger entry using the JavaScript SDK
📄️ Retrieve a contract code ledger entry using the Python SDK
Retrieve a contract code ledger entry using the Python SDK