Skip to main content

Overview

The Provider interface and AnchorProvider class manage the wallet and network context for Anchor programs. They handle transaction signing, sending, and confirmation.

Provider Interface

The base Provider 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 the Provider 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.
This method is only available in Node.js environments. It reads the wallet from ~/.config/solana/id.json.
() => AnchorProvider
Creates a provider from the ANCHOR_PROVIDER_URL environment variable. Node.js only.
This method is only available in Node.js environments and requires the ANCHOR_PROVIDER_URL environment variable to be set.

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

The Wallet 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.

Usage Examples

Setting Up a Provider

Sending Transactions

Simulating Transactions

Browser Integration