Query on-chain data
These functions basically construct the graphQL query to fetch the indexer data, which listens all events related to the program and stores the data in a database.
import {
queryPurchases,
queryAccounts,
queryEvents,
queryTransactions,
AccountType
} from "brick-protocol"
import dotenv from 'dotenv';
dotenv.config();
// Provides user purchases and sales, discriminate sales and purchases by checking
// the signer of the event. You can use these filters:
export type UserTranasctionFilters = {
user: string
startDate?: number
endDate?: number
limit?: number
skip?: number
reverse?: boolean
}
async function queryTransaction() {
const filters: UserTranasctionFilters = { user: "rikiFB2VznT2izUT7UffzWCn1X4gNmGutX7XEqFdpRR" };
await queryTransactions('http://localhost:8080', filters);
}
// Provides you the instruction history of an specific account (can be a user o a program account).
// You can use these filters:
export type EventsFilters = {
account: string
types?: InstructionType[]
signer?: string
startDate?: number
endDate?: number
limit?: number
skip?: number
reverse?: boolean
}
async function queryEvent() {
const filters = { account: "5WnQLqDpc35PodFDBH6ZAWzDonvt4SF9R9wHq7mhMBG" };
await queryEvents('http://localhost:8080', filters);
}
// Provides accounts information. You can use these filters:
export type AccountsFilters = {
types?: AccountType[]
accounts?: string[]
authorities?: string[]
includeStats?: boolean
}
async function queryAccount() {
const filters = { types: [AccountType.Marketplace] };
await queryAccounts('http://localhost:8080', filters);
}
// queryPurchases does API requests using DAS
async function queryPurchase() {
const RPC = process.env.RPC || '';
if (RPC === '') throw new Error("RPC not found in environment variables.");
const owner = 'fisherH6SRzYVd2JE53Kgiax9R9MmtS95TC8ERPr3D7';
const productMint = 'FuzwPRVgY9TAgJR5KY58hDb9D4Y3VfNFYHfsW3gDMyJW';
const accessesPurchased = await queryPurchases(RPC, owner, productMint);
}
Last updated