getTransactionType
Determines the transaction type based on transaction fields
getTransactionType
Determines the transaction type based on the transaction fields. Returns the transaction type string.
Import
import "github.com/ChefBingbong/viem-go/utils/transaction"import "math/big"Usage
import "github.com/ChefBingbong/viem-go/utils/transaction"import "math/big"
tx := &transaction.Transaction{ MaxFeePerGas: big.NewInt(1000000000),}
txType, err := transaction.GetTransactionType(tx)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
transaction (required)
- Type:
*transaction.Transaction
The transaction object to analyze.
tx := &transaction.Transaction{ MaxFeePerGas: big.NewInt(1000000000),}
txType, _ := transaction.GetTransactionType(tx)Type Detection Logic
The transaction type is determined in the following order:
- Explicit Type: If
tx.Typeis set, it's returned directly - EIP-7702: If
AuthorizationListis present - EIP-4844: If blob-related fields are present (
Blobs,BlobVersionedHashes,MaxFeePerBlobGas,Sidecars) - EIP-1559: If
MaxFeePerGasorMaxPriorityFeePerGasis present - EIP-2930: If
GasPriceandAccessListare present - Legacy: If
GasPriceis present withoutAccessList - Error: If none of the above conditions are met
Functions
GetTransactionType
Returns the transaction type:
txType, _ := transaction.GetTransactionType(tx)
MustGetTransactionType
Returns the transaction type or panics:
txType := transaction.MustGetTransactionType(tx)