connect() must be called and WalletConnect session must be initiated before account information will be returned.
connect()
The getRecords() function returns records for the currently selected account. A filter can be applied to return a subset of records.
getRecords()
import { RecordsFilter, getRecords, GetRecordsResponse, RecordWithPlaintext, useAccount} from '@puzzlehq/sdk';import { useState } from 'react'; export const RecordsPage = () => { const [loading, setLoading] = useState(false); const [error, setError] = useState<string | undefined>(); const [records, setRecords] = useState<RecordWithPlaintext[] | undefined>(); const [totalPageCount, setTotalPageCount] = useState(0); const filter: RecordsFilter = { programId: 'credits.aleo'; type: 'unspent'; } const onClick = async () => { setLoading(true); setError(undefined); try { const response: GetRecordsResponse = await getRecords({ filter, address: "aleo1t5ympyhrn6rgk7d0h0ktvmvzlymsnwg6w0c0ns5nac7s8d39x5qqtlaynz" }); setRecords(response.records); setTotalPageCount(response.pageCount); } catch (e) { setError((e as Error).message); } finally { setLoading(false); } } return ( <div> <button onClick={ onClick } disabled={ loading } > fetch records </button> { records && ( <div> <p>there are {totalPageCount} pages of records</p> {records.map((record) => { <p>{record.plaintext}</p> })} </div> )} { error && <p>error fetching recirds: {error}</p> } </div> )}
type RecordWithPlaintext = { _id: string; // database id for record eventId: string; // database id for associated Event height: number; // block height ciphertext: string; network: Network; name: string; // record name: e.g. Credit programId: string; functionId: string; transitionId: string; transactionId: string; owner: string; spent: boolean; serialNumber?: string; plaintext: string; data: { [key: string]: string }; // JSON object representing plaintext data}; type RecordsFilter = { programId?: string; function?: string; type: 'all' | 'spent' | 'unspent';}; type GetRecordsRequest = { address?: string; // defaults to the currently selected account. Can be used to return a shared-state account's records. filter?: RecordsFilter; // defaults to all records page?: number;}; type GetRecordsResponse = { records?: Record[]; // records that meet filter criteria pageCount?: number; // total page count of all records that meet criteria error?: string;};