Home Reference Source
import {Connection} from '@solana/web3'
public class | source

Connection

A connection to a fullnode JSON RPC endpoint

Constructor Summary

Public Constructor
public

constructor(endpoint: string, commitment: Commitment)

Establish a JSON RPC connection

Member Summary

Public Members
public get

The default commitment used for requests

Method Summary

Public Methods
public

async confirmTransaction(signature: TransactionSignature, confirmations: number): Promise<RpcResponseAndContext<SignatureStatus|nullliteral>>

Confirm the transaction identified by the specified signature

public

async getAccountInfo(publicKey: PublicKey, commitment: Commitment): Promise<AccountInfo|nullliteral>

Fetch all the account info for the specified public key

public

async getAccountInfoAndContext(publicKey: PublicKey, commitment: Commitment): Promise<RpcResponseAndContext<AccountInfo|nullliteral>>

Fetch all the account info for the specified public key, return with context

public

async getBalance(publicKey: PublicKey, commitment: Commitment): Promise<number>

Fetch the balance for the specified public key

public

Fetch the balance for the specified public key, return with context

public

async getBlockTime(slot: number): Promise<number|nullliteral>

Fetch the estimated production time of a block

public

Return the list of nodes that are currently participating in the cluster

public

Fetch a list of Transactions and transaction statuses from the cluster for a confirmed block

public

Fetch a list of all the confirmed signatures for transactions involving an address within a specified slot range.

public

Fetch a transaction details for a confirmed transaction

public

async getEpochInfo(commitment: Commitment): Promise<EpochInfo>

Fetch the Epoch Info parameters

public

Fetch the Epoch Schedule parameters

public

async getFeeCalculatorForBlockhash(blockhash: Blockhash, commitment: Commitment): Promise<RpcResponseAndContext<FeeCalculator|nullliteral>>

Fetch the fee calculator for a recent blockhash from the cluster, return with context

public

Fetch the slot of the lowest confirmed block that has not been purged from the ledger

public

Fetch the cluster InflationGovernor parameters

public

Fetch the 20 largest accounts with their current balances

public

Fetch the leader schedule for the current epoch

public

Fetch the minimum balance needed to exempt an account of dataLength size from rent

public

Fetch the lowest slot that the node has information about in its ledger.

public

async getNonce(nonceAccount: PublicKey, commitment: Commitment): Promise<NonceAccount|nullliteral>

Fetch the contents of a Nonce account from the cluster

public

async getNonceAndContext(nonceAccount: PublicKey, commitment: Commitment): Promise<RpcResponseAndContext<NonceAccount|nullliteral>>

Fetch the contents of a Nonce account from the cluster, return with context

public

async getProgramAccounts(programId: PublicKey, commitment: Commitment): Promise<Array<{pubkey: PublicKey, account: AccountInfo}>>

Fetch all the accounts owned by the specified program id

public

async getRecentBlockhash(commitment: Commitment): Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>

Fetch a recent blockhash from the cluster

public

Fetch a recent blockhash from the cluster, return with context

public

async getSignatureStatus(signature: TransactionSignature, config: SignatureStatusConfig): Promise<RpcResponseAndContext<SignatureStatus|nullliteral>>

Fetch the current status of a signature

public

async getSignatureStatuses(signatures: Array<TransactionSignature>, config: SignatureStatusConfig): Promise<RpcResponseAndContext<Array<SignatureStatus|nullliteral>>>

Fetch the current statuses of a batch of signatures

public

async getSlot(commitment: Commitment): Promise<number>

Fetch the current slot that the node is processing

public

async getSlotLeader(commitment: Commitment): Promise<string>

Fetch the current slot leader of the cluster

public

Fetch information about the current supply

public

Fetch the current balance of a token account

public

async getTokenAccountsByOwner(ownerAddress: PublicKey, filter: TokenAccountsFilter, commitment: Commitment): Promise<RpcResponseAndContext<Array<{pubkey: PublicKey, account: TokenAccount}>>>

Fetch all the token accounts owned by the specified account

public

async getTokenSupply(tokenMintAddress: PublicKey, commitment: Commitment): Promise<RpcResponseAndContext<number>>

Fetch the current supply of a token mint

public

async getTotalSupply(commitment: Commitment): Promise<number>

Fetch the current total currency supply of the cluster in lamports

public

Fetch the current transaction count of the cluster

public

Fetch the node version

public

Return the list of nodes that are currently participating in the cluster

public

onAccountChange(publicKey: PublicKey, callback: AccountChangeCallback, commitment: Commitment): number

Register a callback to be invoked whenever the specified account changes

public

onProgramAccountChange(programId: PublicKey, callback: ProgramAccountChangeCallback, commitment: Commitment): number

Register a callback to be invoked whenever accounts owned by the specified program change

public

onRootChange(callback: RootChangeCallback): number

Register a callback to be invoked upon root changes

public

onSignature(signature: TransactionSignature, callback: SignatureResultCallback, commitment: Commitment): number

Register a callback to be invoked upon signature updates

public

onSlotChange(callback: SlotChangeCallback): number

Register a callback to be invoked upon slot changes

public

Deregister an account notification callback

public

Deregister an account notification callback

public

Deregister a root notification callback

public

Deregister a signature notification callback

public

Deregister a slot notification callback

public

Request an allocation of lamports to the specified account

public

async sendEncodedTransaction(encodedTransaction: string, options: SendOptions): Promise<TransactionSignature>

Send a transaction that has already been signed, serialized into the wire format, and encoded as a base58 string

public

async sendRawTransaction(rawTransaction: Buffer | Uint8Array | Array<number>, options: SendOptions): Promise<TransactionSignature>

Send a transaction that has already been signed and serialized into the wire format

public

async sendTransaction(transaction: Transaction, signers: Array<Account>, options: SendOptions): Promise<TransactionSignature>

Sign and send a transaction

Public Constructors

public constructor(endpoint: string, commitment: Commitment) source

Establish a JSON RPC connection

Params:

NameTypeAttributeDescription
endpoint string

URL to the fullnode JSON RPC endpoint

commitment Commitment
  • nullable: true

optional default commitment level

Public Members

public get commitment: Commitment source

The default commitment used for requests

Public Methods

public async confirmTransaction(signature: TransactionSignature, confirmations: number): Promise<RpcResponseAndContext<SignatureStatus|nullliteral>> source

Confirm the transaction identified by the specified signature

Params:

NameTypeAttributeDescription
signature TransactionSignature
confirmations number
  • nullable: true

Return:

Promise<RpcResponseAndContext<SignatureStatus|nullliteral>>

public async getAccountInfo(publicKey: PublicKey, commitment: Commitment): Promise<AccountInfo|nullliteral> source

Fetch all the account info for the specified public key

Params:

NameTypeAttributeDescription
publicKey PublicKey
commitment Commitment
  • nullable: true

Return:

Promise<AccountInfo|nullliteral>

public async getAccountInfoAndContext(publicKey: PublicKey, commitment: Commitment): Promise<RpcResponseAndContext<AccountInfo|nullliteral>> source

Fetch all the account info for the specified public key, return with context

Params:

NameTypeAttributeDescription
publicKey PublicKey
commitment Commitment
  • nullable: true

Return:

Promise<RpcResponseAndContext<AccountInfo|nullliteral>>

public async getBalance(publicKey: PublicKey, commitment: Commitment): Promise<number> source

Fetch the balance for the specified public key

Params:

NameTypeAttributeDescription
publicKey PublicKey
commitment Commitment
  • nullable: true

Return:

Promise<number>

public async getBalanceAndContext(publicKey: PublicKey, commitment: Commitment): Promise<RpcResponseAndContext<number>> source

Fetch the balance for the specified public key, return with context

Params:

NameTypeAttributeDescription
publicKey PublicKey
commitment Commitment
  • nullable: true

public async getBlockTime(slot: number): Promise<number|nullliteral> source

Fetch the estimated production time of a block

Params:

NameTypeAttributeDescription
slot number

Return:

Promise<number|nullliteral>

public async getClusterNodes(): Promise<Array<ContactInfo>> source

Return the list of nodes that are currently participating in the cluster

public async getConfirmedBlock(slot: number): Promise<ConfirmedBlock> source

Fetch a list of Transactions and transaction statuses from the cluster for a confirmed block

Params:

NameTypeAttributeDescription
slot number

public async getConfirmedSignaturesForAddress(address: PublicKey, startSlot: number, endSlot: number): Promise<Array<TransactionSignature>> source

Fetch a list of all the confirmed signatures for transactions involving an address within a specified slot range. Max range allowed is 10,000 slots.

Params:

NameTypeAttributeDescription
address PublicKey

queried address

startSlot number

start slot, inclusive

endSlot number

end slot, inclusive

public async getConfirmedTransaction(signature: TransactionSignature): Promise<ConfirmedTransaction|nullliteral> source

Fetch a transaction details for a confirmed transaction

Params:

NameTypeAttributeDescription
signature TransactionSignature

Return:

Promise<ConfirmedTransaction|nullliteral>

public async getEpochInfo(commitment: Commitment): Promise<EpochInfo> source

Fetch the Epoch Info parameters

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

Return:

Promise<EpochInfo>

public async getEpochSchedule(): Promise<EpochSchedule> source

Fetch the Epoch Schedule parameters

public async getFeeCalculatorForBlockhash(blockhash: Blockhash, commitment: Commitment): Promise<RpcResponseAndContext<FeeCalculator|nullliteral>> source

Fetch the fee calculator for a recent blockhash from the cluster, return with context

Params:

NameTypeAttributeDescription
blockhash Blockhash
commitment Commitment
  • nullable: true

Return:

Promise<RpcResponseAndContext<FeeCalculator|nullliteral>>

public async getFirstAvailableBlock(): Promise<number> source

Fetch the slot of the lowest confirmed block that has not been purged from the ledger

Return:

Promise<number>

public async getInflationGovernor(commitment: Commitment): Promise<InflationGovernor> source

Fetch the cluster InflationGovernor parameters

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

public async getLargestAccounts(config: GetLargestAccountsConfig): Promise<RpcResponseAndContext<Array<AccountBalancePair>>> source

Fetch the 20 largest accounts with their current balances

Params:

NameTypeAttributeDescription
config GetLargestAccountsConfig
  • nullable: true

public async getLeaderSchedule(): Promise<RpcResponseAndContext<LeaderSchedule>> source

Fetch the leader schedule for the current epoch

public async getMinimumBalanceForRentExemption(dataLength: number, commitment: Commitment): Promise<number> source

Fetch the minimum balance needed to exempt an account of dataLength size from rent

Params:

NameTypeAttributeDescription
dataLength number
commitment Commitment
  • nullable: true

Return:

Promise<number>

public async getMinimumLedgerSlot(): Promise<number> source

Fetch the lowest slot that the node has information about in its ledger. This value may increase over time if the node is configured to purge older ledger data

Return:

Promise<number>

public async getNonce(nonceAccount: PublicKey, commitment: Commitment): Promise<NonceAccount|nullliteral> source

Fetch the contents of a Nonce account from the cluster

Params:

NameTypeAttributeDescription
nonceAccount PublicKey
commitment Commitment
  • nullable: true

Return:

Promise<NonceAccount|nullliteral>

public async getNonceAndContext(nonceAccount: PublicKey, commitment: Commitment): Promise<RpcResponseAndContext<NonceAccount|nullliteral>> source

Fetch the contents of a Nonce account from the cluster, return with context

Params:

NameTypeAttributeDescription
nonceAccount PublicKey
commitment Commitment
  • nullable: true

Return:

Promise<RpcResponseAndContext<NonceAccount|nullliteral>>

public async getProgramAccounts(programId: PublicKey, commitment: Commitment): Promise<Array<{pubkey: PublicKey, account: AccountInfo}>> source

Fetch all the accounts owned by the specified program id

Params:

NameTypeAttributeDescription
programId PublicKey
commitment Commitment
  • nullable: true

Return:

Promise<Array<{pubkey: PublicKey, account: AccountInfo}>>

public async getRecentBlockhash(commitment: Commitment): Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}> source

Fetch a recent blockhash from the cluster

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

Return:

Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>

public async getRecentBlockhashAndContext(commitment: Commitment): Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>> source

Fetch a recent blockhash from the cluster, return with context

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

Return:

Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>

public async getSignatureStatus(signature: TransactionSignature, config: SignatureStatusConfig): Promise<RpcResponseAndContext<SignatureStatus|nullliteral>> source

Fetch the current status of a signature

Params:

NameTypeAttributeDescription
signature TransactionSignature
config SignatureStatusConfig
  • nullable: true

Return:

Promise<RpcResponseAndContext<SignatureStatus|nullliteral>>

public async getSignatureStatuses(signatures: Array<TransactionSignature>, config: SignatureStatusConfig): Promise<RpcResponseAndContext<Array<SignatureStatus|nullliteral>>> source

Fetch the current statuses of a batch of signatures

Params:

NameTypeAttributeDescription
signatures Array<TransactionSignature>
config SignatureStatusConfig
  • nullable: true

Return:

Promise<RpcResponseAndContext<Array<SignatureStatus|nullliteral>>>

public async getSlot(commitment: Commitment): Promise<number> source

Fetch the current slot that the node is processing

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

Return:

Promise<number>

public async getSlotLeader(commitment: Commitment): Promise<string> source

Fetch the current slot leader of the cluster

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

Return:

Promise<string>

public async getSupply(commitment: Commitment): Promise<RpcResponseAndContext<Supply>> source

Fetch information about the current supply

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

public async getTokenAccountBalance(tokenAddress: PublicKey, commitment: Commitment): Promise<RpcResponseAndContext<number>> source

Fetch the current balance of a token account

Params:

NameTypeAttributeDescription
tokenAddress PublicKey
commitment Commitment
  • nullable: true

public async getTokenAccountsByOwner(ownerAddress: PublicKey, filter: TokenAccountsFilter, commitment: Commitment): Promise<RpcResponseAndContext<Array<{pubkey: PublicKey, account: TokenAccount}>>> source

Fetch all the token accounts owned by the specified account

Params:

NameTypeAttributeDescription
ownerAddress PublicKey
filter TokenAccountsFilter
commitment Commitment
  • nullable: true

Return:

Promise<RpcResponseAndContext<Array<{pubkey: PublicKey, account: TokenAccount}>>>

public async getTokenSupply(tokenMintAddress: PublicKey, commitment: Commitment): Promise<RpcResponseAndContext<number>> source

Fetch the current supply of a token mint

Params:

NameTypeAttributeDescription
tokenMintAddress PublicKey
commitment Commitment
  • nullable: true

public async getTotalSupply(commitment: Commitment): Promise<number> source

Fetch the current total currency supply of the cluster in lamports

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

Return:

Promise<number>

public async getTransactionCount(commitment: Commitment): Promise<number> source

Fetch the current transaction count of the cluster

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

Return:

Promise<number>

public async getVersion(): Promise<Version> source

Fetch the node version

Return:

Promise<Version>

public async getVoteAccounts(commitment: Commitment): Promise<VoteAccountStatus> source

Return the list of nodes that are currently participating in the cluster

Params:

NameTypeAttributeDescription
commitment Commitment
  • nullable: true

public onAccountChange(publicKey: PublicKey, callback: AccountChangeCallback, commitment: Commitment): number source

Register a callback to be invoked whenever the specified account changes

Params:

NameTypeAttributeDescription
publicKey PublicKey

Public key of the account to monitor

callback AccountChangeCallback

Function to invoke whenever the account is changed

commitment Commitment
  • nullable: true

Specify the commitment level account changes must reach before notification

Return:

number

subscription id

public onProgramAccountChange(programId: PublicKey, callback: ProgramAccountChangeCallback, commitment: Commitment): number source

Register a callback to be invoked whenever accounts owned by the specified program change

Params:

NameTypeAttributeDescription
programId PublicKey

Public key of the program to monitor

callback ProgramAccountChangeCallback

Function to invoke whenever the account is changed

commitment Commitment
  • nullable: true

Specify the commitment level account changes must reach before notification

Return:

number

subscription id

public onRootChange(callback: RootChangeCallback): number source

Register a callback to be invoked upon root changes

Params:

NameTypeAttributeDescription
callback RootChangeCallback

Function to invoke whenever the root changes

Return:

number

subscription id

public onSignature(signature: TransactionSignature, callback: SignatureResultCallback, commitment: Commitment): number source

Register a callback to be invoked upon signature updates

Params:

NameTypeAttributeDescription
signature TransactionSignature

Transaction signature string in base 58

callback SignatureResultCallback

Function to invoke on signature notifications

commitment Commitment
  • nullable: true

Specify the commitment level signature must reach before notification

Return:

number

subscription id

public onSlotChange(callback: SlotChangeCallback): number source

Register a callback to be invoked upon slot changes

Params:

NameTypeAttributeDescription
callback SlotChangeCallback

Function to invoke whenever the slot changes

Return:

number

subscription id

public async removeAccountChangeListener(id: number): Promise<void> source

Deregister an account notification callback

Params:

NameTypeAttributeDescription
id number

subscription id to deregister

Return:

Promise<void>

public async removeProgramAccountChangeListener(id: number): Promise<void> source

Deregister an account notification callback

Params:

NameTypeAttributeDescription
id number

subscription id to deregister

Return:

Promise<void>

public async removeRootChangeListener(id: number): Promise<void> source

Deregister a root notification callback

Params:

NameTypeAttributeDescription
id number

subscription id to deregister

Return:

Promise<void>

public async removeSignatureListener(id: number): Promise<void> source

Deregister a signature notification callback

Params:

NameTypeAttributeDescription
id number

subscription id to deregister

Return:

Promise<void>

public async removeSlotChangeListener(id: number): Promise<void> source

Deregister a slot notification callback

Params:

NameTypeAttributeDescription
id number

subscription id to deregister

Return:

Promise<void>

public async requestAirdrop(to: PublicKey, amount: number): Promise<TransactionSignature> source

Request an allocation of lamports to the specified account

Params:

NameTypeAttributeDescription
to PublicKey
amount number

public async sendEncodedTransaction(encodedTransaction: string, options: SendOptions): Promise<TransactionSignature> source

Send a transaction that has already been signed, serialized into the wire format, and encoded as a base58 string

Params:

NameTypeAttributeDescription
encodedTransaction string
options SendOptions
  • nullable: true

public async sendRawTransaction(rawTransaction: Buffer | Uint8Array | Array<number>, options: SendOptions): Promise<TransactionSignature> source

Send a transaction that has already been signed and serialized into the wire format

Params:

NameTypeAttributeDescription
rawTransaction Buffer | Uint8Array | Array<number>
options SendOptions
  • nullable: true

public async sendTransaction(transaction: Transaction, signers: Array<Account>, options: SendOptions): Promise<TransactionSignature> source

Sign and send a transaction

Params:

NameTypeAttributeDescription
transaction Transaction
signers Array<Account>
options SendOptions