sequencerProvider: Querying the Starknet Sequencer with Starknet.js
The sequencerProvider is a provider class in Starknet.js that connects your application to the Starknet sequencer's HTTP API. It exposes methods for reading chain state, submitting transactions, and—most relevant to finality tracking—checking the status of a transaction with getTransactionStatus(). This page explains how the provider works, how to configure it, and how to use it to monitor transaction lifecycle events.
What the sequencerProvider Does
Starknet.js offers multiple provider implementations. The sequencerProvider targets the sequencer's REST-like endpoints, which are the same endpoints used by the network's gateway. It is useful when you need direct access to sequencer-specific behavior, such as querying transaction status before a receipt is fully available, or when you are working against a local development node that exposes the sequencer API.
Key capabilities include:
- Fetching transaction status and receipts.
- Reading block information and state updates.
- Estimating fees and simulating transactions.
- Interacting with contracts through read calls.
For most new projects, the RpcProvider is the recommended default because it follows the standardized JSON-RPC specification. The sequencerProvider remains valuable for compatibility and for sequencer-specific queries.
Configuring a sequencerProvider Instance
Create a provider by importing the class and supplying a network identifier or a custom base URL. The provider accepts an optional network string (for example, 'goerli-alpha' or 'mainnet-alpha') or a baseUrl pointing to a sequencer endpoint.
import { SequencerProvider } from 'starknet';
const provider = new SequencerProvider({
network: 'goerli-alpha',
});
If you are running a local Starknet devnet, point the provider at its gateway URL instead. Always confirm the network identifier matches the chain you intend to query; mixing networks is a common source of confusing errors.
Using getTransactionStatus() to Track Finality
The getTransactionStatus() method returns the current status of a transaction as seen by the sequencer. It is a lightweight call compared to fetching a full receipt, making it suitable for polling during confirmation workflows.
const status = await provider.getTransactionStatus(transactionHash);
console.log(status);
The response typically includes fields such as finality_status and execution_status. These values tell you whether the transaction has been received, accepted on L2, or is still pending. Because Starknet finality involves both L2 acceptance and eventual L1 settlement, you should treat the sequencer status as one signal among several rather than a complete finality guarantee.
Practical guidance for polling:
- Poll at a reasonable interval (for example, every few seconds) and back off after repeated pending responses.
- Handle transient network errors separately from definitive statuses.
- Combine status checks with receipt retrieval when you need execution details or events.
- Do not assume a status is final until the network's documented finality conditions are met.
Common Methods and When to Use Them
Beyond getTransactionStatus(), the sequencerProvider exposes methods that cover most read operations:
getTransactionReceipt()— retrieve execution results, events, and messages once available.getBlock()— fetch block data by block number or hash.callContract()— perform a read-only contract call.estimateFee()— estimate the fee for a transaction before submission.getEvents()— query events emitted within a block range.
Use getTransactionStatus() when you need a quick lifecycle check, and getTransactionReceipt() when you need the outcome and emitted data. For contract reads, callContract() avoids the overhead of constructing a full transaction.
Error Handling and Best Practices
Sequencer endpoints can return errors for unknown transaction hashes, malformed requests, or rate limiting. Wrap calls in try/catch blocks and inspect the error message. A transaction that is not yet known to the sequencer may simply be propagating; retry with backoff before treating it as failed.
Keep these practices in mind:
- Validate transaction hashes before sending requests.
- Log the raw status response during development to understand field values.
- Avoid hard-coding network URLs; use configuration or environment variables.
- Consider migrating to
RpcProviderfor long-term projects, as JSON-RPC is the forward-looking interface.
Frequently Asked Questions
Is sequencerProvider deprecated?
No. It remains available in Starknet.js, but the library's direction favors RpcProvider for standardized access. Check the migration guides for the version you are using.
Can I use getTransactionStatus() to determine finality?
It provides the sequencer's view of a transaction's status. Finality on Starknet also depends on L1 settlement, so use it as part of a broader confirmation strategy rather than a sole source of truth.
What is the difference between getTransactionStatus() and getTransactionReceipt()?
getTransactionStatus() returns a compact status object. getTransactionReceipt() returns detailed execution information, including events and messages, once the transaction has been processed.
How do I connect to a local devnet?
Pass a baseUrl option pointing to your devnet's sequencer endpoint when constructing the provider.