assertRequest
Validates a transaction request and returns an error if invalid
assertRequest
Validates a transaction request and returns an error if the request is invalid. Checks address validity and fee constraints.
Import
import "github.com/ChefBingbong/viem-go/utils/transaction"import "math/big"Usage
import "github.com/ChefBingbong/viem-go/utils/transaction"import "math/big"
err := transaction.AssertRequest(transaction.AssertRequestParams{ Account: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", To: "0x1234567890123456789012345678901234567890", MaxFeePerGas: big.NewInt(1000000000), MaxPriorityFeePerGas: big.NewInt(100000000),})if err != nil { log.Fatal(err)}Returns
- Type:
error
Returns nil if the request is valid, or an error describing the validation failure.
Parameters
params (required)
- Type:
transaction.AssertRequestParams
The transaction request parameters to validate.
params := transaction.AssertRequestParams{ Account: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", To: "0x1234567890123456789012345678901234567890", MaxFeePerGas: big.NewInt(1000000000), MaxPriorityFeePerGas: big.NewInt(100000000),}
err := transaction.AssertRequest(params)params.Account (optional)
- Type:
string
The account address. Must be a valid Ethereum address format if provided.
params := transaction.AssertRequestParams{ Account: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", // ...}params.To (optional)
- Type:
string
The recipient address. Must be a valid Ethereum address format if provided.
params := transaction.AssertRequestParams{ To: "0x1234567890123456789012345678901234567890", // ...}params.MaxFeePerGas (optional)
- Type:
*big.Int
The maximum fee per gas. Must not exceed max uint256, and must be >= MaxPriorityFeePerGas if both are provided.
params := transaction.AssertRequestParams{ MaxFeePerGas: big.NewInt(1000000000), // ...}params.MaxPriorityFeePerGas (optional)
- Type:
*big.Int
The maximum priority fee per gas. Must not exceed MaxFeePerGas if both are provided.
params := transaction.AssertRequestParams{ MaxPriorityFeePerGas: big.NewInt(100000000), // ...}Validations
This function validates:
- Account Address: Must be a valid 40-character hex address with
0xprefix (if provided) - To Address: Must be a valid 40-character hex address with
0xprefix (if provided) - MaxFeePerGas: Must not exceed max uint256 value
- Fee Constraint:
MaxPriorityFeePerGasmust not exceedMaxFeePerGas(if both are provided)