UNPKG

@solana-developers/helpers

Version:
126 lines 4.62 kB
import { Connection, PublicKey, Keypair, ConfirmOptions } from "@solana/web3.js"; import { Idl, AnchorProvider } from "@coral-xyz/anchor"; /** * Loads an Anchor IDL from a local file path * * @param idlPath - Path to the IDL JSON file * @returns The parsed IDL * * @example * ```typescript * const idl = await getIdlByPath("./idl/program.json"); * ``` */ export declare function getIdlByPath<Idl>(idlPath: string): Promise<Idl>; /** * Fetches an Anchor IDL from a program on-chain * * @param programId - Public key of the program * @param provider - Anchor Provider instance (you can use createProviderForConnection to create) * @returns The fetched IDL * @throws If IDL cannot be found for the program * * @example * ```typescript * const idl = await getIdlByProgramId( * new PublicKey("Foo1111111111111111111111111111111111111"), * connection * ); * ``` */ export declare function getIdlByProgramId<Idl>(programId: PublicKey, provider: AnchorProvider): Promise<Idl>; /** * Creates an Anchor provider for a given connection * * @param connection - The Solana connection object * @param keypair - Optional keypair to use for the provider (defaults to a new random keypair) * @param options - Optional configuration options for the provider * @returns An Anchor provider instance * * @example * ```typescript * const provider = createProviderForConnection(connection); * ``` */ export declare function createProviderForConnection(connection: Connection, keypair?: Keypair, options?: ConfirmOptions): AnchorProvider; /** * Fetches and parses an account's data using an Anchor IDL * * @param idl - The Anchor IDL (use getIdlByProgramId or getIdlByPath to obtain) * @param accountName - The name of the account as defined in the IDL * @param accountAddress - The public key of the account to fetch * @param provider - Anchor Provider instance (you can use createProviderForConnection to create) * @param programId - Optional program ID needed for legacy IDLs * @returns The decoded account data * * @example * ```typescript * const idl = await getIdlByProgramId(programId, connection); * const data = await getIdlParsedAccountData(idl, "counter", accountAddress); * ``` */ export declare function getIdlParsedAccountData<T = any>(idl: Idl, accountName: string, accountAddress: PublicKey, provider: AnchorProvider, programId?: PublicKey): Promise<T>; /** * Parses Anchor events from a transaction * * @param idl - The Anchor IDL (use getIdlByProgramId or getIdlByPath to obtain) * @param signature - Transaction signature to parse events from * @param provider - Anchor Provider instance (you can use createProviderForConnection to create) * @param programId - Optional program ID needed for legacy IDLs * @returns Array of parsed events with their name and data * * @example * ```typescript * const idl = await getIdlByPath("./idl/program.json"); * const events = await parseAnchorTransactionEvents(idl, signature); * ``` */ export declare function parseAnchorTransactionEvents(idl: Idl, signature: string, provider: AnchorProvider, programId?: PublicKey): Promise<Array<{ name: string; data: any; }>>; /** * Account involved in an instruction */ type InvolvedAccount = { name: string; pubkey: string; isSigner: boolean; isWritable: boolean; data?: Record<string, any>; }; /** * Decoded Anchor instruction with all involved accounts */ export type DecodedAnchorInstruction = { name: string; type: string; data: Record<string, any>; accounts: InvolvedAccount[]; toString: () => string; }; /** * Decoded Anchor transaction containing all instructions and their accounts */ export type DecodedTransaction = { instructions: DecodedAnchorInstruction[]; toString: () => string; }; /** * Decodes all Anchor instructions and their involved accounts in a transaction * * @param idl - The Anchor IDL (use getIdlByProgramId or getIdlByPath to obtain) * @param signature - Transaction signature to decode * @param connection - Optional connection object (uses default provider if not specified) * @param programId - Optional program ID needed for legacy IDLs * @returns Decoded transaction with instructions and accounts * * @example * ```typescript * const idl = await getIdlByProgramId(programId, connection); * const decoded = await decodeAnchorTransaction(idl, signature); * ``` */ export declare function decodeAnchorTransaction(idl: Idl, signature: string, provider: AnchorProvider, programId?: PublicKey): Promise<DecodedTransaction>; export {}; //# sourceMappingURL=idl.d.ts.map