Skip to content

BlockWithTxHashes

Gets a block with only transaction hashes (not full transaction details).

Method Signature

func (provider *Provider) BlockWithTxHashes(ctx context.Context, blockID BlockID) (interface{}, error)

Parameters

  • ctx - Context for request cancellation and timeout
  • blockID - Block identifier (number, hash, or tag)

Returns

  • interface{} - Block with transaction hashes only
  • error - Error if the request fails

BlockID Parameter

This method requires a BlockID parameter. The RPC package provides helper functions to create BlockID:

// Using block number
blockID := rpc.WithBlockNumber(123456)
 
// Using block hash
hash, _ := new(felt.Felt).SetString("0x1234...")
blockID := rpc.WithBlockHash(hash)
 
// Using block tag
blockID := rpc.WithBlockTag("latest")
See RPC Helper Functions for detailed documentation of these helper functions.

Usage Example

package main
 
import (
    "context"
    "encoding/json"
    "fmt"
    "log"
	"os"
 
    "github.com/NethermindEth/starknet.go/rpc"
)
 
func main() {
    // Create RPC client
	// Get RPC URL from environment variable
	rpcURL := os.Getenv("STARKNET_RPC_URL")
	if rpcURL == "" {
		log.Fatal("STARKNET_RPC_URL not set in environment")
	}
 
	ctx := context.Background()
    client, err := rpc.NewProvider(ctx, rpcURL)
    if err != nil {
        log.Fatal("Failed to create client:", err)
    }
 
    // Get latest block with transaction hashes
    blockID := rpc.WithBlockTag("latest")
    block, err := client.BlockWithTxHashes(ctx, blockID)
    if err != nil {
        log.Fatal("Failed to get block:", err)
    }
 
    // Pretty print the result
    blockJSON, _ := json.MarshalIndent(block, "", "  ")
    fmt.Printf("Block with transaction hashes:\n%s\n", blockJSON)
}

Expected Output

{
  "block_hash": "0x3e06332a36a380f4e67545bada2819aae004161ad3159c4690c2727715d9a7a",
  "parent_hash": "0x39ed18564ef2222757ee7420de2d55af875419cd5aeb72e7dda2822769d8c4e",
  "block_number": 2732828,
  "new_root": "0xa1e7bc42320acaa5f38738af6495669c714b0d729dac721932e388e595bb33",
  "timestamp": 1761895612,
  "sequencer_address": "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
  "l1_gas_price": {
    "price_in_fri": "0x1b6ea95f1cc1",
    "price_in_wei": "0x3b9aca09"
  },
  "l2_gas_price": {
    "price_in_fri": "0xb2d05e00",
    "price_in_wei": "0x18486"
  },
  "l1_data_gas_price": {
    "price_in_fri": "0x75d2",
    "price_in_wei": "0x1"
  },
  "l1_da_mode": "BLOB",
  "starknet_version": "0.14.0",
  "status": "ACCEPTED_ON_L2",
  "transactions": [
    "0x233dc4da3ba77d376a8a1fcf5148a363d3e74f4e9e2b067639423256dc6ba05",
    "0x570a52ecce4fc29d1691f3369542ea65d9044601786b12d1cc8552e9ebd4fdd",
    "0x3fdb2993c2fc4c5cff3e27e896de8a25b02ef5b2b19434ee09d39d4d7a05904",
    "0x198f321e4309105dc59c78bd74f56e58b391bcb424d7de239da0a37e99d7f72",
    "0x4fa8857855849d69f1c17b801936595e0d2f678601931b8052d2a9b54595ef",
    "0x3dab28aebebd0e8b402f00dfff992f81abb33fe4742df92b5d7023df6ba79f6",
    "0x39ffc3f0e6cbfa6e026053bb7a5ae0576334e03e57e00a12c45a81c526d018a",
    "0x3000f042c46894427e5c229356cb3a35bdf4e1aa52a09dd19afcbaf5918f8d",
    "0x34d7b28aed546fa7908434633aea495d414089e6864b569441414ab22762887",
    "0x5e3382e52776adcf6d4843700802672581923098ef56e7bb26d7003dbed00fd",
    "0x79200f9161a85dee82728e7a3bb7619948f2fa50faa36d261819174ad3e72b4",
    "0x770115392f3e12a8226758086e8108e8fc89730d19efa5a5f2a9a81cbf06698"
  ]
}

This block contains 12 transactions with only the hashes shown (instead of full transaction details).

Error Handling

block, err := client.BlockWithTxHashes(ctx, blockID)
if err != nil {
    log.Printf("Error getting block with tx hashes: %v", err)
    return
}
 
fmt.Printf("Successfully retrieved block with transaction hashes\n")