Overview
TheProvider interface and AnchorProvider class manage the wallet and network context for Anchor programs. They handle transaction signing, sending, and confirmation.
Provider Interface
The baseProvider interface defines the contract for network and wallet interactions.
Properties
Connection
required
The Solana RPC connection to the cluster.
PublicKey
The public key of the wallet, if available.
Wallet
The wallet instance used for signing transactions.
AnchorProvider
The standard implementation of theProvider interface.
Constructor
(connection, wallet, opts?) => AnchorProvider
Creates a new AnchorProvider instance.
Static Methods
() => ConfirmOptions
Returns the default confirmation options.
(url?, opts?) => AnchorProvider
Creates a provider with a wallet from the local filesystem. Node.js only.
() => AnchorProvider
Creates a provider from the
ANCHOR_PROVIDER_URL environment variable. Node.js only.Instance Properties
Connection
The Solana cluster connection.
Wallet
The wallet instance for signing transactions.
PublicKey
The public key of the wallet.
ConfirmOptions
Default transaction confirmation options.
Methods
async (tx, signers?, opts?) => Promise<TransactionSignature>
Sends a transaction, waits for confirmation, and returns the signature.
async (txWithSigners, opts?) => Promise<TransactionSignature[]>
Sends multiple transactions in parallel and waits for all confirmations.
async (tx, signers?, commitment?, includeAccounts?) => Promise<SuccessfulTxSimulationResponse>
Simulates a transaction without sending it to the network.
Wallet Interface
TheWallet interface defines how wallets sign transactions.
async (tx) => Promise<Transaction | VersionedTransaction>
Signs a single transaction.
async (txs) => Promise<(Transaction | VersionedTransaction)[]>
Signs multiple transactions.
PublicKey
The wallet’s public key.
Helper Functions
(provider) => void
Sets the global default provider.
() => Provider
Gets the current global provider.