Skip to main content
Version: 5.19.5

RPC Provider

Creating an instance​

new starknet.RpcProvider(options)

  • options.nodeUrl - Starknet RPC node url
  • options.headers - [Optional] custom fetch headers
  • options.retries - [Optional] wait for transaction max retries
  • options.blockIdentifier - [Optional] default value set to 'latest'

Example:

const provider = new starknet.RpcProvider({
nodeUrl: 'URL_TO_STARKNET_RPC_NODE',
});

Methods​


fetch()​

provider.fetch(method: any, params: any) => Promise < any >

Generic method for users to be able to experiment with RPC methods.


getChainId()​

provider.getChainId() => Promise < any >


getBlock()​

provider.getBlock(blockIdentifier) => Promise < GetBlockResponse >


getBlockHashAndNumber()​

provider.getBlockHashAndNumber() => Promise < BlockHashAndNumber >

BlockHashAndNumber​
{
block_hash: BLOCK_HASH;
block_number: BLOCK_NUMBER;
}

getBlockWithTxHashes()​

provider.getBlockWithTxHashes(blockIdentifier) => Promise < GetBlockWithTxHashesResponse >

GetBlockWithTxHashesResponse​
OPENRPC.BlockWithTxHashes;

getBlockWithTxs()​

provider.getBlockWithTxs(blockIdentifier) => Promise < GetBlockWithTxs >

GetBlockWithTxs​
OPENRPC.BlockWithTxs;

getClassHashAt()​

provider.getClassHashAt(blockIdentifier) => Promise < ContractAddress >


getTransactionCount()​

provider.getTransactionCount(blockIdentifier) => Promise < number >

Gets the transaction count from a block.


getBlockNumber()​

provider.getBlockNumber() => Promise < number >

Gets the latest block number.


getPendingTransactions()​

provider.getPendingTransactions() => Promise < PendingTransactions >

PendingTransactions​
OPENRPC.PendingTransactions;

getStateUpdate()​

provider.getStateUpdate(blockIdentifier) => Promise < StateUpdate >

StateUpdate​
OPENRPC.StateUpdate;

getStorageAt()​

provider.getStorageAt(contractAddress, key, blockIdentifier) => Promise < BigNumberish >


getTransaction()​

provider.getTransaction(txHash) => Promise < GetTransactionResponse >


getTransactionByHash()​

provider.getTransactionByHash(txHash) => Promise < GetTransactionByHashResponse >

GetTransactionByHashResponse​
OPENRPC.Transaction;

getTransactionByBlockIdAndIndex()​

provider.getTransactionByBlockIdAndIndex(blockIdentifier, index) => Promise < GetTransactionByBlockIdAndIndex >

GetTransactionByBlockIdAndIndex​
OPENRPC.Transaction;

getTransactionReceipt()​

provider.getTransactionReceipt(txHash) => Promise < GetTransactionReceiptResponse >


getClass()​

provider.getClass(classHash) => Promise < ContractClass >

ContractClass​
OPENRPC.ContractClass;

getClassAt()​

provider.getClassAt(contractAddress, blockIdentifier) => Promise < ContractClass >

ContractClass​
OPENRPC.ContractClass;

getInvokeEstimateFee()​

provider.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier) => Promise < EstimateFeeResponse >

EstimateFeeResponse​
  overall_fee: BN;
gas_consumed?: BN;
gas_price?: BN;

getDeclareEstimateFee()​

provider.getDeclareEstimateFee(DeclareContractTransaction, details, blockIdentifier) => Promise < EstimateFeeResponse >

EstimateFeeResponse​
  overall_fee: BN;
gas_consumed?: BN;
gas_price?: BN;

declareContract()​

provider.declareContract(DeclareContractTransaction, details) => Promise < DeclareContractResponse >

DeclareContractResponse​
transaction_hash: string;
class_hash: string;

callContract()​

provider.callContract(call, blockIdentifier) => Promise < CallContractResponse >


getContractAddresses()​

provider.traceTransaction(transactionHash) => Promise < Trace >

Trace​
OPENRPC.Trace;

traceBlockTransactions()​

provider.traceBlockTransactions(blockHash) => Promise < Traces >

Traces​
OPENRPC.Traces;

getSyncingStats()​

provider.getSyncingStats() => Promise < GetSyncingStatsResponse >

Gets syncing status of the node.

GetSyncingStatsResponse​
boolean |
{
starting_block_hash: string;
starting_block_num: string;
current_block_hash: string;
current_block_num: string;
highest_block_hash: string;
highest_block_num: string;
}

getEvents()​

provider.getEvents(eventFilter) => Promise < GetEventsResponse >

Gets all the events filtered

EventFilter​
type EventFilter = {
fromBlock: string;
toBlock: string;
address: string;
keys: string[];
page_size: number;
page_number: number;
};
GetEventsResponse​
{
events: StarknetEmittedEvent[];
page_number: number;
is_last_page: number;
}