getContractData method

Future<LedgerEntry?> getContractData(
  1. String contractId,
  2. XdrSCVal key,
  3. XdrContractDataDurability durability
)
inherited

Reads the current value of contract data ledger entries directly. Requires the contractId of the contract containing the data to load, the key of the contract data to load, The durability keyspace that this ledger key belongs to, which is either XdrContractDataDurability.TEMPORARY or XdrContractDataDurability.PERSISTENT

Implementation

Future<LedgerEntry?> getContractData(String contractId, XdrSCVal key,
    XdrContractDataDurability durability) async {
  XdrLedgerKey ledgerKey = XdrLedgerKey(XdrLedgerEntryType.CONTRACT_DATA);
  ledgerKey.contractData = XdrLedgerKeyContractData(
      Address.forContractId(contractId).toXdr(), key, durability);
  GetLedgerEntriesResponse ledgerEntriesResponse =
      await getLedgerEntries([ledgerKey.toBase64EncodedXdrString()]);
  if (ledgerEntriesResponse.entries != null &&
      ledgerEntriesResponse.entries!.length > 0) {
    return ledgerEntriesResponse.entries![0];
  }
  return null;
}