Once your IDL has been generated, you can import it and create an instance of your Program in Typescript.
Import your generated IDL file, in this case from /target/types/basic_counter.ts
Use the anchorWallet from the previous step to create an AnchorProvider.
Report incorrect code
Copy
Ask AI
import { BasicCounter as BasicCounterProgram } from "../../basic-counter/target/types/basic_counter";import { AnchorProvider, Program } from "@coral-xyz/anchor";const COUNTER_PROGRAM_ID = "ADraQ2ENAbVoVZhvH5SPxWPsF2hH5YmFcgx61TafHuwu";// Address of the devnet-deployed Counter Programconst counterProgramId = useMemo(() => { return new PublicKey(COUNTER_PROGRAM_ID);}, []);// Create an AnchorProvider with the anchorWallet.const provider = useMemo(() => { if (!anchorWallet) { return null; } return new AnchorProvider(connection, anchorWallet, { preflightCommitment: "confirmed", commitment: "processed", });}, [anchorWallet, connection]);// Create an instance of your Program.const counterProgram = useMemo(() => { if (!provider) { return null; } return new Program<BasicCounterProgram>( idl as BasicCounterProgram, counterProgramId, provider );}, [counterProgramId, provider]);
Calling the rpc() will generate and sign the transaction using the interface methods (signTransaction, signAllTransactions) of the Anchor Wallet that the program was instantiated with.