getTransactionType
Determines the transaction type based on transaction fields
Loading...
Determines the transaction type based on transaction fields
Determines the transaction type based on the transaction fields. Returns the transaction type string.
import "github.com/ChefBingbong/viem-go/utils/transaction"import "math/big"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: eip1559(transaction.TransactionType, error)The transaction type: "legacy", "eip2930", "eip1559", "eip4844", or "eip7702".
*transaction.TransactionThe transaction object to analyze.
tx := &transaction.Transaction{ MaxFeePerGas: big.NewInt(1000000000),}
txType, _ := transaction.GetTransactionType(tx)The transaction type is determined in the following order:
tx.Type is set, it's returned directlyAuthorizationList is presentBlobs, BlobVersionedHashes, MaxFeePerBlobGas, Sidecars)MaxFeePerGas or MaxPriorityFeePerGas is presentGasPrice and AccessList are presentGasPrice is present without AccessListReturns the transaction type:
txType, _ := transaction.GetTransactionType(tx)
Returns the transaction type or panics:
txType := transaction.MustGetTransactionType(tx)