assertTransaction
Validates a transaction object and returns an error if invalid
Loading...
Validates a transaction object and returns an error if invalid
Validates a transaction object and returns an error if the transaction is invalid. Different validation functions exist for each transaction type.
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{ Type: transaction.TransactionTypeEIP1559, ChainId: 1, Nonce: 0, MaxFeePerGas: big.NewInt(1000000000), MaxPriorityFeePerGas: big.NewInt(100000000), Gas: big.NewInt(21000), To: "0x1234512345123451234512345123451234512345", Value: big.NewInt(0),}
// Assert EIP-1559 transactionerr := transaction.AssertTransactionEIP1559(tx)if err != nil { log.Fatal(err)}errorReturns nil if the transaction is valid, or an error describing the validation failure.
*transaction.TransactionThe transaction object to validate.
tx := &transaction.Transaction{ ChainId: 1, MaxFeePerGas: big.NewInt(1000000000), MaxPriorityFeePerGas: big.NewInt(100000000), Gas: big.NewInt(21000), To: "0x1234512345123451234512345123451234512345",}
err := transaction.AssertTransactionEIP1559(tx)Validates an EIP-1559 transaction:
To address must be valid (if present)MaxFeePerGas must not exceed max uint256MaxPriorityFeePerGas must not exceed MaxFeePerGasValidates an EIP-2930 transaction:
To address must be valid (if present)GasPrice must not exceed max uint256Validates an EIP-4844 transaction:
Validates an EIP-7702 transaction:
Validates a legacy transaction:
To address must be valid (if present)GasPrice must not exceed max uint256All transaction types validate:
To is present)