getBlockWithTxs
Action for getting Starknet block information including transactions.
Import
import { getBlockWithTxs } from "starkweb/core";
Usage
index.ts
import { getBlockWithTxs } from "starkweb/core";
import { config } from "./config";
const block = await getBlockWithTxs(config, {
blockIdentifier: "latest",
});
console.log("Block transactions:", block.transactions);
Parameters
import { type GetBlockWithTxsParameters } from "starkweb/core";
blockIdentifier
BlockIdentifier
The block identifier (number, hash, or 'latest').
index.ts
import { getBlockWithTxs } from "starkweb/core";
import { config } from "./config";
// Get latest block
const latestBlock = await getBlockWithTxs(config, {
blockIdentifier: "latest",
});
// Get block by number
const blockByNumber = await getBlockWithTxs(config, {
blockIdentifier: 123456n,
});
// Get block by hash
const blockByHash = await getBlockWithTxs(config, {
blockIdentifier: "0xabcdef...",
});
chainId (optional)
Hex | undefined
The chain ID to get the block for. If not provided, uses the current chain.
index.ts
import { getBlockWithTxs } from "starkweb/core";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
const block = await getBlockWithTxs(config, {
blockIdentifier: "latest",
chainId: mainnet.chain_id,
});
Return Type
import { type GetBlockWithTxsReturnType } from "starkweb/core";
Returns block information including all transactions and chain ID:
transactions
Transaction[]
Array of transactions included in the block.
chainId
Hex
The chain ID of the network.
block_hash
Hex
The hash of the block.
parent_hash
Hex
The hash of the parent block.
block_number
bigint
The number of the block.
Example
example.ts
import { getBlockWithTxs } from "starkweb/core";
import { mainnet, testnet } from "starkweb/chains";
import { config } from "./config";
// Get latest block with transactions
const latestBlock = await getBlockWithTxs(config, {
blockIdentifier: "latest",
});
console.log({
blockNumber: latestBlock.block_number,
transactionCount: latestBlock.transactions.length,
});
// Get specific block from mainnet
const mainnetBlock = await getBlockWithTxs(config, {
blockIdentifier: 123456n,
chainId: mainnet.chain_id,
});
// Process block transactions
mainnetBlock.transactions.forEach((tx, index) => {
console.log(`Transaction ${index + 1}:`, tx.transaction_hash);
});
Error
import { type GetBlockWithTxsErrorType } from "starkweb/core";