TransactionReceipt
Gets the execution receipt of a transaction by its hash. The receipt contains execution results including success/failure status, actual fees paid, gas consumed, events emitted, messages sent, and detailed revert reasons if the transaction failed. This is essential for verifying transaction execution, analyzing costs, and debugging failed transactions.
Method Signature
func (provider *Provider) TransactionReceipt(
ctx context.Context,
transactionHash *felt.Felt,
) (*TransactionReceiptWithBlockInfo, error)Source: transaction.go
Parameters
ctx(context.Context): Context for request cancellation and timeouttransactionHash(*felt.Felt): The transaction hash to get the receipt for
Returns
*TransactionReceiptWithBlockInfo: Transaction receipt with execution details and block informationerror: Error if the request fails
Type Definitions
TransactionReceiptWithBlockInfo
type TransactionReceiptWithBlockInfo struct {
TransactionReceipt
BlockHash *felt.Felt `json:"block_hash,omitempty"`
BlockNumber uint `json:"block_number,omitempty"`
}Source: types_transaction_receipt.go
Usage Example
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/joho/godotenv"
)
func main() {
// Load environment variables from .env file
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
// Get RPC URL from environment variable
rpcURL := os.Getenv("STARKNET_RPC_URL")
if rpcURL == "" {
log.Fatal("STARKNET_RPC_URL not found in .env file")
}
// Initialize provider
provider, err := rpc.NewProvider(context.Background(), rpcURL)
if err != nil {
log.Fatal(err)
}
// Parse transaction hash
txHashStr := "0x6dda0d2e2716227b87d912d654e1bc8b96441f043c29834e082413ae1320afa"
txHash, err := new(felt.Felt).SetString(txHashStr)
if err != nil {
log.Fatal(err)
}
// Get transaction receipt
receipt, err := provider.TransactionReceipt(context.Background(), txHash)
if err != nil {
log.Fatal(err)
}
// Pretty print the result
receiptJSON, _ := json.MarshalIndent(receipt, "", " ")
fmt.Printf("Transaction receipt:\n%s\n", receiptJSON)
}Error Handling
receipt, err := provider.TransactionReceipt(ctx, txHash)
if err != nil {
switch {
case errors.Is(err, rpc.ErrHashNotFound):
log.Printf("Transaction not found")
default:
log.Printf("Failed to get receipt: %v", err)
}
return
}
// Check execution status
executionStatus := receipt.TransactionReceipt.ExecutionStatus()
if executionStatus == "REVERTED" {
fmt.Printf("Transaction failed\n")
if revertReason := receipt.TransactionReceipt.RevertReason(); revertReason != "" {
fmt.Printf("Revert reason: %s\n", revertReason)
}
} else {
fmt.Printf("Transaction succeeded\n")
}Common Use Cases
This method is commonly used for:
- Verifying if a transaction executed successfully.
- Analyzing actual gas consumption and fees paid. See example.

