Learn how to integrate Para with Solana Anchor Framework for interacting with on-chain programs.
The Anchor Frameworkis a popular development framework for building Solana programs that simplifies the development process with features like IDL integration and type safety. This guide will show you how to integrate Para’s wallet and signing capabilities with Anchor.
To use Para, you need an API key. This key authenticates your requests to Para services and is essential for integration. Before integrating Para with your application, ensure you have:
Completed Para authentication setup in your application (see one of our Setup Guides)
A valid Para API key
An RPC endpoint for your desired network
Need an API key? Visit the Developer Portal to create API keys, manage billing, teams, and more.
To use Para with Anchor, you need to create a custom signer that integrates with Anchor’s wallet system. Below is an example of how to set up the Para signer with Anchor using the ParaSolanaWeb3Signer class. You can reference the Para Solana Web3.js Integration guide for more details on the signer setup.
Copy
Ask AI
import { ParaSolanaWeb3Signer } from "@getpara/solana-web3.js-v1-integration";import { Connection, clusterApiUrl, Transaction, VersionedTransaction, SystemProgram } from "@solana/web3.js";import * as anchor from "@project-serum/anchor";import { para } from "./para"; // Your Para client initializationconst solanaConnection = new Connection(clusterApiUrl("testnet"));const solanaSigner = new ParaSolanaWeb3Signer(para, solanaConnection);const anchorWallet = { publicKey: solanaSigner.sender, signTransaction: async <T extends Transaction | VersionedTransaction>(tx: T): Promise<T> => { return await solanaSigner.signTransaction(tx); }, signAllTransactions: async <T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]> => { return await Promise.all(txs.map((tx) => solanaSigner.signTransaction(tx))); },};const provider = new anchor.AnchorProvider( solanaConnection, anchorWallet, { commitment: "confirmed" });// Set the provider globallyanchor.setProvider(provider);
Once you’ve set up the provider, you can initialize and interact with your Anchor program:
Copy
Ask AI
// Initialize the programconst program = new anchor.Program(idl as YourProgramImport, provider);// Now you can call your program's methodstry { // Example: Create Token const tx = await program.methods .createToken(tokenName, tokenSymbol) .accounts({ payer: solanSigner.sender, mintAccount: mintKeypair.publicKey, tokenProgram: TOKEN_2022_PROGRAM_ID, systemProgram: SystemProgram.programId, rent: anchor.web3.SYSVAR_RENT_PUBKEY, }) .signers([mintKeypair]) .rpc(); console.log("Transaction signature:", tx);} catch (error) { console.error("Error calling program method:", error);}
We encourage you check out the Anchor documentation for more details on how to define your IDL, accounts, and methods.
Para only acts as the signer for the transaction and does not handle the program logic or state. Constructing transactions and interacting with the program is entirely up to you. Ensure you have the correct program IDL and account structures defined in your Anchor program.
Para’s signers can also be used on the server-side with Anchor using pregen wallets or an active client-side session. To learn more about using Para on the server, check out these guides: