Skip to main content
Version: 5.24.3

Class: RpcProvider

Implements​

Constructors​

constructor​

β€’ new RpcProvider(optionsOrProvider?)

Parameters​

NameType
optionsOrProvider?RpcProviderOptions

Defined in​

src/provider/rpc.ts:73

Properties​

nodeUrl​

β€’ nodeUrl: string

Defined in​

src/provider/rpc.ts:61


headers​

β€’ headers: object

Defined in​

src/provider/rpc.ts:63


responseParser​

β€’ Private responseParser: RPCResponseParser

Defined in​

src/provider/rpc.ts:65


retries​

β€’ Private retries: number

Defined in​

src/provider/rpc.ts:67


blockIdentifier​

β€’ Private blockIdentifier: BlockIdentifier

Defined in​

src/provider/rpc.ts:69


chainId​

β€’ Private Optional chainId: StarknetChainId

Defined in​

src/provider/rpc.ts:71


getBlockHashAndNumber​

β€’ getBlockHashAndNumber: () => Promise<BlockHashAndNumber>

Type declaration​

β–Έ (): Promise<BlockHashAndNumber>

Deprecated

renamed to getBlockLatestAccepted(); (will be removed in next minor version)

Returns​

Promise<BlockHashAndNumber>

Defined in​

src/provider/rpc.ts:171


getStateUpdate​

β€’ getStateUpdate: (blockIdentifier: BlockIdentifier) => Promise<PENDING_STATE_UPDATE | STATE_UPDATE>

Type declaration​

β–Έ (blockIdentifier?): Promise<PENDING_STATE_UPDATE | STATE_UPDATE>

Deprecated

renamed to getBlockStateUpdate();

Parameters​
NameType
blockIdentifierBlockIdentifier
Returns​

Promise<PENDING_STATE_UPDATE | STATE_UPDATE>

Implementation of​

ProviderInterface.getStateUpdate

Defined in​

src/provider/rpc.ts:207


traceBlockTransactions​

β€’ traceBlockTransactions: (blockIdentifier: BlockIdentifier) => Promise<BlockTransactionsTraces>

Type declaration​

β–Έ (blockIdentifier?): Promise<BlockTransactionsTraces>

Returns the execution traces of all transactions included in the given block

Deprecated

renamed to getBlockTransactionsTraces()

Parameters​
NameType
blockIdentifierBlockIdentifier
Returns​

Promise<BlockTransactionsTraces>

Defined in​

src/provider/rpc.ts:218


getTransactionCount​

β€’ getTransactionCount: (blockIdentifier: BlockIdentifier) => Promise<number>

Type declaration​

β–Έ (blockIdentifier?): Promise<number>

Get the number of transactions in a block given a block id

Deprecated

renamed to getBlockTransactionCount()

Parameters​
NameType
blockIdentifierBlockIdentifier
Returns​

Promise<number>

Number of transactions

Defined in​

src/provider/rpc.ts:230


traceTransaction​

β€’ traceTransaction: (txHash: BigNumberish) => Promise<TRANSACTION_TRACE>

Type declaration​

β–Έ (txHash): Promise<TRANSACTION_TRACE>

Deprecated

renamed to getTransactionTrace(); For a given executed transaction, return the trace of its execution, including internal calls

Parameters​
NameType
txHashBigNumberish
Returns​

Promise<TRANSACTION_TRACE>

Defined in​

src/provider/rpc.ts:274


getSimulateTransaction​

β€’ getSimulateTransaction: (invocations: AccountInvocations, __namedParameters: getSimulateTransactionOptions) => Promise<SimulateTransactionResponse>

Type declaration​

β–Έ (invocations, Β«destructuredΒ»): Promise<SimulateTransactionResponse>

Deprecated

renamed to simulateTransaction();

Parameters​
NameType
invocationsAccountInvocations
Β«destructuredΒ»getSimulateTransactionOptions
Returns​

Promise<SimulateTransactionResponse>

Implementation of​

ProviderInterface.getSimulateTransaction

Defined in​

src/provider/rpc.ts:287

Methods​

fetch​

β–Έ fetch(method, params?, id?): Promise<Response>

Parameters​

NameTypeDefault value
methodstringundefined
params?objectundefined
idstring | number0

Returns​

Promise<Response>

Defined in​

src/provider/rpc.ts:91


errorHandler​

β–Έ Protected errorHandler(method, params, rpcError?, otherError?): void

Parameters​

NameType
methodstring
paramsany
rpcError?Error
otherError?any

Returns​

void

Defined in​

src/provider/rpc.ts:105


fetchEndpoint​

β–Έ Protected fetchEndpoint<T>(method, params?): Promise<Methods[T][``"result"``]>

Type parameters​

NameType
Textends keyof ReadMethods | keyof WriteMethods | keyof TraceMethods

Parameters​

NameType
methodT
params?Methods[T][``"params"``]

Returns​

Promise<Methods[T][``"result"``]>

Defined in​

src/provider/rpc.ts:120


getChainId​

β–Έ getChainId(): Promise<StarknetChainId>

Gets the Starknet chain Id

Returns​

Promise<StarknetChainId>

the chain Id

Implementation of​

ProviderInterface.getChainId

Defined in​

src/provider/rpc.ts:135


getSpecVersion​

β–Έ getSpecVersion(): Promise<string>

NEW: Returns the version of the Starknet JSON-RPC specification being used

Returns​

Promise<string>

Defined in​

src/provider/rpc.ts:143


getNonceForAddress​

β–Έ getNonceForAddress(contractAddress, blockIdentifier?): Promise<string>

Returns the nonce associated with the given address in the given block

Parameters​

NameTypeDescription
contractAddressBigNumberishcontract address
blockIdentifierBlockIdentifier-

Returns​

Promise<string>

the hex nonce

Implementation of​

ProviderInterface.getNonceForAddress

Defined in​

src/provider/rpc.ts:147


getBlock​

β–Έ getBlock(blockIdentifier?): Promise<GetBlockResponse>

Deprecated

use getBlockWithTxHashes or getBlockWithTxs (will be removed on sequencer deprecation)

Parameters​

NameType
blockIdentifierBlockIdentifier

Returns​

Promise<GetBlockResponse>

Implementation of​

ProviderInterface.getBlock

Defined in​

src/provider/rpc.ts:162


getBlockLatestAccepted​

β–Έ getBlockLatestAccepted(): Promise<BlockHashAndNumber>

Get the most recent accepted block hash and number

Returns​

Promise<BlockHashAndNumber>

Defined in​

src/provider/rpc.ts:176


getBlockNumber​

β–Έ getBlockNumber(): Promise<number>

Deprecated

redundant use getBlockLatestAccepted(); Get the most recent accepted block number

Returns​

Promise<number>

Number of the latest block

Defined in​

src/provider/rpc.ts:185


getBlockWithTxHashes​

β–Έ getBlockWithTxHashes(blockIdentifier?): Promise<BlockWithTxHashes>

Parameters​

NameType
blockIdentifierBlockIdentifier

Returns​

Promise<BlockWithTxHashes>

Defined in​

src/provider/rpc.ts:189


getBlockWithTxs​

β–Έ getBlockWithTxs(blockIdentifier?): Promise<BlockWithTxs>

Parameters​

NameType
blockIdentifierBlockIdentifier

Returns​

Promise<BlockWithTxs>

Defined in​

src/provider/rpc.ts:194


getBlockStateUpdate​

β–Έ getBlockStateUpdate(blockIdentifier?): Promise<PENDING_STATE_UPDATE | STATE_UPDATE>

Parameters​

NameType
blockIdentifierBlockIdentifier

Returns​

Promise<PENDING_STATE_UPDATE | STATE_UPDATE>

Defined in​

src/provider/rpc.ts:199


getBlockTransactionsTraces​

β–Έ getBlockTransactionsTraces(blockIdentifier?): Promise<BlockTransactionsTraces>

Parameters​

NameType
blockIdentifierBlockIdentifier

Returns​

Promise<BlockTransactionsTraces>

Defined in​

src/provider/rpc.ts:209


getBlockTransactionCount​

β–Έ getBlockTransactionCount(blockIdentifier?): Promise<number>

Parameters​

NameType
blockIdentifierBlockIdentifier

Returns​

Promise<number>

Defined in​

src/provider/rpc.ts:220


getPendingTransactions​

β–Έ getPendingTransactions(): Promise<TransactionWithHash[]>

Return transactions from pending block

Deprecated

Instead use getBlock(BlockTag.pending); (will be removed in next minor version)

Returns​

Promise<TransactionWithHash[]>

Defined in​

src/provider/rpc.ts:236


getTransaction​

β–Έ getTransaction(txHash): Promise<InvokeTransactionResponse | DeclareTransactionResponse | RejectedTransactionResponse>

Deprecated

use getTransactionByHash or getTransactionByBlockIdAndIndex (will be removed on sequencer deprecation)

Parameters​

NameType
txHashBigNumberish

Returns​

Promise<InvokeTransactionResponse | DeclareTransactionResponse | RejectedTransactionResponse>

Implementation of​

ProviderInterface.getTransaction

Defined in​

src/provider/rpc.ts:244


getTransactionByHash​

β–Έ getTransactionByHash(txHash): Promise<TransactionWithHash>

Parameters​

NameType
txHashBigNumberish

Returns​

Promise<TransactionWithHash>

Defined in​

src/provider/rpc.ts:248


getTransactionByBlockIdAndIndex​

β–Έ getTransactionByBlockIdAndIndex(blockIdentifier, index): Promise<TransactionWithHash>

Parameters​

NameType
blockIdentifierBlockIdentifier
indexnumber

Returns​

Promise<TransactionWithHash>

Defined in​

src/provider/rpc.ts:255


getTransactionReceipt​

β–Έ getTransactionReceipt(txHash): Promise<TransactionReceipt>

Gets the transaction receipt from a tx hash.

Parameters​

NameType
txHashBigNumberish

Returns​

Promise<TransactionReceipt>

the transaction receipt object

Implementation of​

ProviderInterface.getTransactionReceipt

Defined in​

src/provider/rpc.ts:260


getTransactionTrace​

β–Έ getTransactionTrace(txHash): Promise<TRANSACTION_TRACE>

Parameters​

NameType
txHashBigNumberish

Returns​

Promise<TRANSACTION_TRACE>

Defined in​

src/provider/rpc.ts:265


getTransactionStatus​

β–Έ getTransactionStatus(transactionHash): Promise<TransactionStatus>

NEW: Get the status of a transaction

Parameters​

NameType
transactionHashBigNumberish

Returns​

Promise<TransactionStatus>

Defined in​

src/provider/rpc.ts:279


simulateTransaction​

β–Έ simulateTransaction(invocations, simulateTransactionOptions): Promise<SimulateTransactionResponse>

Parameters​

NameTypeDescription
invocationsAccountInvocationsAccountInvocations
simulateTransactionOptionsgetSimulateTransactionOptionsblockIdentifier and flags to skip validation and fee charge
- blockIdentifier
- skipValidate (default false)
- skipFeeCharge (default true)

Returns​

Promise<SimulateTransactionResponse>

Defined in​

src/provider/rpc.ts:296


waitForTransaction​

β–Έ waitForTransaction(txHash, options?): Promise<TransactionReceipt>

Wait for the transaction to be accepted

Parameters​

NameTypeDescription
txHashBigNumberishtransaction hash
options?waitForTransactionOptionswaitForTransactionOptions - (optional) retryInterval: number | undefined; - (optional) successStates: TransactionStatus[] | undefined;

Returns​

Promise<TransactionReceipt>

GetTransactionReceiptResponse

Implementation of​

ProviderInterface.waitForTransaction

Defined in​

src/provider/rpc.ts:316


getStorageAt​

β–Έ getStorageAt(contractAddress, key, blockIdentifier?): Promise<string>

Get the value of the storage (contract's variable) at the given address and key

Parameters​

NameTypeDescription
contractAddressBigNumberish
keyBigNumberishfrom getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
blockIdentifierBlockIdentifierblock identifier

Returns​

Promise<string>

the value of the storage variable

Implementation of​

ProviderInterface.getStorageAt

Defined in​

src/provider/rpc.ts:393


getClassHashAt​

β–Έ getClassHashAt(contractAddress, blockIdentifier?): Promise<string>

Returns the contract class hash in the given block for the contract deployed at the given address

Parameters​

NameTypeDescription
contractAddressBigNumberishcontract address
blockIdentifierBlockIdentifierblock identifier

Returns​

Promise<string>

Class hash

Implementation of​

ProviderInterface.getClassHashAt

Defined in​

src/provider/rpc.ts:408


getClassByHash​

β–Έ getClassByHash(classHash): Promise<LegacyContractClass | Omit<CompiledSierra, "sierra_program_debug_info">>

Returns the contract class deployed under the given class hash.

Parameters​

NameTypeDescription
classHashBigNumberishclass hash

Returns​

Promise<LegacyContractClass | Omit<CompiledSierra, "sierra_program_debug_info">>

Contract class of compiled contract

Implementation of​

ProviderInterface.getClassByHash

Defined in​

src/provider/rpc.ts:420


getClass​

β–Έ getClass(classHash, blockIdentifier?): Promise<LegacyContractClass | Omit<CompiledSierra, "sierra_program_debug_info">>

Parameters​

NameType
classHashBigNumberish
blockIdentifierBlockIdentifier

Returns​

Promise<LegacyContractClass | Omit<CompiledSierra, "sierra_program_debug_info">>

Defined in​

src/provider/rpc.ts:424


getClassAt​

β–Έ getClassAt(contractAddress, blockIdentifier?): Promise<LegacyContractClass | Omit<CompiledSierra, "sierra_program_debug_info">>

Gets the contract class of the deployed contract.

Parameters​

NameTypeDescription
contractAddressBigNumberishcontract address
blockIdentifierBlockIdentifierblock identifier

Returns​

Promise<LegacyContractClass | Omit<CompiledSierra, "sierra_program_debug_info">>

Contract class of compiled contract

Implementation of​

ProviderInterface.getClassAt

Defined in​

src/provider/rpc.ts:436


getCode​

β–Έ getCode(_contractAddress, _blockIdentifier?): Promise<GetCodeResponse>

Deprecated

The method should not be used

Parameters​

NameType
_contractAddressstring
_blockIdentifier?BlockIdentifier

Returns​

Promise<GetCodeResponse>

Implementation of​

ProviderInterface.getCode

Defined in​

src/provider/rpc.ts:448


getContractVersion​

β–Έ getContractVersion(contractAddress, classHash?, options?): Promise<ContractVersion>

Gets the contract version from the provided address

Parameters​

NameTypeDescription
contractAddressBigNumberishstring
classHash?undefinedundefined
options?getContractVersionOptionsgetContractVersionOptions - (optional) compiler - (default true) extract compiler version using type tactic from abi - (optional) blockIdentifier - block identifier

Returns​

Promise<ContractVersion>

Implementation of​

ProviderInterface.getContractVersion

Defined in​

src/provider/rpc.ts:455

β–Έ getContractVersion(contractAddress, classHash, options?): Promise<ContractVersion>

Gets the contract version from the provided address

Parameters​

NameTypeDescription
contractAddressundefinedundefined
classHashBigNumberish
options?getContractVersionOptionsgetContractVersionOptions - (optional) compiler - (default true) extract compiler version using type tactic from abi - (optional) blockIdentifier - block identifier

Returns​

Promise<ContractVersion>

Implementation of​

ProviderInterface.getContractVersion

Defined in​

src/provider/rpc.ts:460


getEstimateFee​

β–Έ getEstimateFee(invocation, invocationDetails, blockIdentifier?): Promise<EstimateFeeResponse>

Deprecated

use gettypeEstimateFee (will be refactored based on type after sequencer deprecation)

Parameters​

NameType
invocationInvocation
invocationDetailsInvocationsDetailsWithNonce
blockIdentifierBlockIdentifier

Returns​

Promise<EstimateFeeResponse>

Implementation of​

ProviderInterface.getEstimateFee

Defined in​

src/provider/rpc.ts:493


getInvokeEstimateFee​

β–Έ getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier?): Promise<EstimateFeeResponse>

Estimates the fee for a given INVOKE transaction

Parameters​

NameTypeDescription
invocationInvocationthe invocation object containing: - contractAddress - the address of the contract - entrypoint - the entrypoint of the contract - calldata - (defaults to []) the calldata - signature - (defaults to []) the signature
invocationDetailsInvocationsDetailsWithNonceoptional details containing: - nonce - optional nonce - version - optional version
blockIdentifierBlockIdentifier(optional) block identifier

Returns​

Promise<EstimateFeeResponse>

the estimated fee

Implementation of​

ProviderInterface.getInvokeEstimateFee

Defined in​

src/provider/rpc.ts:501


getDeclareEstimateFee​

β–Έ getDeclareEstimateFee(invocation, details, blockIdentifier?): Promise<EstimateFeeResponse>

Estimates the fee for a given DECLARE transaction

Parameters​

NameTypeDescription
invocationDeclareContractTransactiontransaction payload to be declared containing: - compiled contract code - sender address - signature - (defaults to []) the signature
detailsInvocationsDetailsWithNonceoptional details containing: - nonce - version - optional version - optional maxFee
blockIdentifierBlockIdentifier(optional) block identifier

Returns​

Promise<EstimateFeeResponse>

the estimated fee

Implementation of​

ProviderInterface.getDeclareEstimateFee

Defined in​

src/provider/rpc.ts:521


getDeployAccountEstimateFee​

β–Έ getDeployAccountEstimateFee(invocation, details, blockIdentifier?): Promise<EstimateFeeResponse>

Estimates the fee for a given DEPLOY_ACCOUNT transaction

Parameters​

NameTypeDescription
invocationDeployAccountContractTransactiontransaction payload to be deployed containing: - classHash - constructorCalldata - addressSalt - signature - (defaults to []) the signature
detailsInvocationsDetailsWithNonceoptional details containing: - nonce - version - optional version - optional maxFee
blockIdentifierBlockIdentifier(optional) block identifier

Returns​

Promise<EstimateFeeResponse>

the estimated fee

Implementation of​

ProviderInterface.getDeployAccountEstimateFee

Defined in​

src/provider/rpc.ts:541


getEstimateFeeBulk​

β–Έ getEstimateFeeBulk(invocations, Β«destructuredΒ»): Promise<EstimateFeeResponseBulk>

Estimates the fee for a list of INVOKE transaction

Parameters​

NameTypeDescription
invocationsAccountInvocationsAccountInvocations - Complete invocations array with account details
Β«destructuredΒ»getEstimateFeeBulkOptionsgetEstimateFeeBulkOptions - (optional) blockIdentifier - BlockIdentifier - (optional) skipValidate - boolean (default false)

Returns​

Promise<EstimateFeeResponseBulk>

the estimated fee

Implementation of​

ProviderInterface.getEstimateFeeBulk

Defined in​

src/provider/rpc.ts:561


invokeFunction​

β–Έ invokeFunction(functionInvocation, details): Promise<InvokedTransaction>

Invokes a function on starknet

Deprecated

This method won't be supported as soon as fees are mandatory. Should not be used outside of Account class

Parameters​

NameTypeDescription
functionInvocationInvocationthe invocation object containing: - contractAddress - the address of the contract - entrypoint - the entrypoint of the contract - calldata - (defaults to []) the calldata - signature - (defaults to []) the signature
detailsInvocationsDetailsWithNonceoptional details containing: - nonce - optional nonce - version - optional version - maxFee - optional maxFee

Returns​

Promise<InvokedTransaction>

response from addTransaction

Implementation of​

ProviderInterface.invokeFunction

Defined in​

src/provider/rpc.ts:576


declareContract​

β–Έ declareContract(Β«destructuredΒ», details): Promise<DeclaredTransaction>

Declares a given compiled contract (json) to starknet

Parameters​

NameTypeDescription
Β«destructuredΒ»DeclareContractTransactiontransaction payload to be deployed containing: - compiled contract code - sender address - signature
detailsInvocationsDetailsWithNonceInvocation Details containing: - nonce - optional version - optional maxFee

Returns​

Promise<DeclaredTransaction>

a confirmation of sending a transaction on the starknet contract

Implementation of​

ProviderInterface.declareContract

Defined in​

src/provider/rpc.ts:593


deployAccountContract​

β–Έ deployAccountContract(Β«destructuredΒ», details): Promise<DeployedAccountTransaction>

Deploys a given compiled Account contract (json) to starknet

Parameters​

NameTypeDescription
Β«destructuredΒ»DeployAccountContractTransactionpayload to be deployed containing: - compiled contract code - constructor calldata - address salt
detailsInvocationsDetailsWithNonce-

Returns​

Promise<DeployedAccountTransaction>

a confirmation of sending a transaction on the starknet contract

Implementation of​

ProviderInterface.deployAccountContract

Defined in​

src/provider/rpc.ts:633


callContract​

β–Έ callContract(call, blockIdentifier?): Promise<CallContractResponse>

Calls a function on the Starknet contract.

Parameters​

NameTypeDescription
callCalltransaction to be called
blockIdentifierBlockIdentifierblock identifier

Returns​

Promise<CallContractResponse>

the result of the function on the smart contract.

Implementation of​

ProviderInterface.callContract

Defined in​

src/provider/rpc.ts:651


estimateMessageFee​

β–Έ estimateMessageFee(message, blockIdentifier?): Promise<FEE_ESTIMATE>

NEW: Estimate the fee for a message from L1

Parameters​

NameTypeDescription
messageMSG_FROM_L1Message From L1
blockIdentifierBlockIdentifier-

Returns​

Promise<FEE_ESTIMATE>

Defined in​

src/provider/rpc.ts:669


getSyncingStats​

β–Έ getSyncingStats(): Promise<Syncing>

Returns an object about the sync status, or false if the node is not synching

Returns​

Promise<Syncing>

Object with the stats data

Defined in​

src/provider/rpc.ts:692


getEvents​

β–Έ getEvents(eventFilter): Promise<EVENTS_CHUNK>

Returns all events matching the given filter

Parameters​

NameType
eventFilterEventFilter

Returns​

Promise<EVENTS_CHUNK>

events and the pagination of the events

Defined in​

src/provider/rpc.ts:700


getStarkName​

β–Έ getStarkName(address, StarknetIdContract?): Promise<string>

StarknetId Endpoint (get name from address)

Parameters​

NameType
addressBigNumberish
StarknetIdContract?string

Returns​

Promise<string>

Defined in​

src/provider/rpc.ts:707


getAddressFromStarkName​

β–Έ getAddressFromStarkName(name, StarknetIdContract?): Promise<string>

StarknetId Endpoint (get address from name)

Parameters​

NameType
namestring
StarknetIdContract?string

Returns​

Promise<string>

Defined in​

src/provider/rpc.ts:714


buildTransaction​

β–Έ buildTransaction(invocation, versionType?): BROADCASTED_TXN

Parameters​

NameType
invocationAccountInvocationItem
versionType?"fee" | "transaction"

Returns​

BROADCASTED_TXN

Defined in​

src/provider/rpc.ts:718