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)

Establish a JSON RPC connection

Method Summary

Public Methods
public

Confirm the transaction identified by the specified signature

public

Fetch all the account info for the specified public key

public

async getBalance(publicKey: PublicKey): Promise<number>

Fetch the balance for the specified public key

public

async getRecentBlockhash(): Promise<Blockhash>

Fetch a recent blockhash from the cluster

public

Fetch the current transaction count of the cluster

public

Fetch the current transaction count of the cluster

public

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

Register a callback to be invoked whenever the specified account changes

public

Deregister an account notification callback

public

Request an allocation of tokens to the specified account

public

async sendRawTransaction(rawTransaction: Buffer): Promise<TransactionSignature>

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

public

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

Sign and send a transaction

Public Constructors

public constructor(endpoint: string) source

Establish a JSON RPC connection

Params:

NameTypeAttributeDescription
endpoint string

URL to the fullnode JSON RPC endpoint

Public Methods

public async confirmTransaction(signature: TransactionSignature): Promise<boolean> source

Confirm the transaction identified by the specified signature

Params:

NameTypeAttributeDescription
signature TransactionSignature

Return:

Promise<boolean>

public async getAccountInfo(publicKey: PublicKey): Promise<AccountInfo> source

Fetch all the account info for the specified public key

Params:

NameTypeAttributeDescription
publicKey PublicKey

Return:

Promise<AccountInfo>

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

Fetch the balance for the specified public key

Params:

NameTypeAttributeDescription
publicKey PublicKey

Return:

Promise<number>

public async getRecentBlockhash(): Promise<Blockhash> source

Fetch a recent blockhash from the cluster

Return:

Promise<Blockhash>

public async getSignatureStatus(signature: TransactionSignature): Promise<SignatureStatus> source

Fetch the current transaction count of the cluster

Params:

NameTypeAttributeDescription
signature TransactionSignature

public async getTransactionCount(): Promise<number> source

Fetch the current transaction count of the cluster

Return:

Promise<number>

public onAccountChange(publicKey: PublicKey, callback: AccountChangeCallback): 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

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 requestAirdrop(to: PublicKey, amount: number): Promise<TransactionSignature> source

Request an allocation of tokens to the specified account

Params:

NameTypeAttributeDescription
to PublicKey
amount number

public async sendRawTransaction(rawTransaction: Buffer): Promise<TransactionSignature> source

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

Params:

NameTypeAttributeDescription
rawTransaction Buffer

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

Sign and send a transaction

Params:

NameTypeAttributeDescription
transaction Transaction
signers ...Array<Account>