getSerializedTransactionType
Determines the transaction type from a serialized transaction
getSerializedTransactionType
Determines the transaction type from a serialized transaction hex string by examining the type prefix.
Import
import "github.com/ChefBingbong/viem-go/utils/transaction"Usage
import "github.com/ChefBingbong/viem-go/utils/transaction"
// Get type from serialized transactiontxType, err := transaction.GetSerializedTransactionType("0x02ef0182031184773594008477359400809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c0")if err != nil { log.Fatal(err)}fmt.Printf("Type: %s", txType)// Type: eip1559Returns
- Type:
(transaction.TransactionType, error)
The transaction type: "legacy", "eip2930", "eip1559", "eip4844", or "eip7702".
Parameters
serializedTransaction (required)
- Type:
string
The serialized transaction hex string.
txType, _ := transaction.GetSerializedTransactionType("0x02ef0182031184773594008477359400809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c0")Type Detection
The transaction type is determined from the first byte(s) of the serialized transaction:
- Legacy: No type prefix (starts with RLP data)
- EIP-2930:
0x01prefix - EIP-1559:
0x02prefix - EIP-4844:
0x03prefix - EIP-7702:
0x04prefix
Notes
- This function only examines the type prefix, not the transaction fields
- For determining type from a transaction object, use
GetTransactionTypeinstead - Returns an error if the serialized transaction format is invalid