extensions/erc20approvalgassponsor
import "github.com/x402-foundation/x402/go/v2/extensions/erc20approvalgassponsor"
Package erc20approvalgassponsor provides types and helpers for the ERC-20 Approval Gas Sponsoring extension.
This extension enables gasless approval of the Permit2 contract for ERC-20 tokens that do NOT implement EIP-2612. Instead of an off-chain signature, the client creates a signed (but unbroadcast) approve(Permit2, MaxUint256) transaction. The facilitator broadcasts it before calling settle().
Constants
ERC20ApprovalGasSponsoringVersion is the current schema version for the extension info.
Source: extensions/erc20approvalgassponsor/types.go:20
const ERC20ApprovalGasSponsoringVersion = "1"Variables
ERC20ApprovalGasSponsoring is the extension identifier for the ERC-20 approval gas sponsoring extension.
Source: extensions/erc20approvalgassponsor/types.go:17
var ERC20ApprovalGasSponsoring = x402.NewFacilitatorExtension("erc20ApprovalGasSponsoring")Functions
func DeclareExtension() map[string]interface{}
Source: extensions/erc20approvalgassponsor/declare.go:14
DeclareExtension creates the extension declaration for inclusion in PaymentRequired.extensions.
The server advertises that it (or its facilitator) supports ERC-20 approval gas sponsoring. The client will sign and attach the approve transaction data.
Returns a map keyed by the extension identifier.
Example:
extensions := erc20approvalgassponsor.DeclareExtension()
// Include in PaymentRequired.Extensionsfunc ExtractInfo(extensions map[string]interface{}) (*Info, error)
Source: extensions/erc20approvalgassponsor/extract.go:21
ExtractInfo extracts the ERC-20 approval gas sponsoring info from a payment payload's extensions map.
Returns the info if the extension is present and contains the required client-populated fields, or nil if not present or incomplete.
func ValidateInfo(info *Info) bool
Source: extensions/erc20approvalgassponsor/extract.go:63
ValidateInfo validates that the ERC-20 approval gas sponsoring info has valid format.
Types
type Erc20ApprovalFacilitatorExtension
Source: extensions/erc20approvalgassponsor/types.go:92
Erc20ApprovalFacilitatorExtension carries the signer; registered with the facilitator. It implements x402.FacilitatorExtension so it can be registered and retrieved via FacilitatorContext.
type Erc20ApprovalFacilitatorExtension struct {
Signer Erc20ApprovalGasSponsoringSigner
// Optional network-aware signer resolver. When provided, this takes precedence
// over Signer and allows different settlement signers per network.
SignerForNetwork func(network string) Erc20ApprovalGasSponsoringSigner
}Fields
Signer Erc20ApprovalGasSponsoringSignerSignerForNetwork func(network string) Erc20ApprovalGasSponsoringSignerOptional network-aware signer resolver. When provided, this takes precedence over Signer and allows different settlement signers per network.
func Key() string
Source: extensions/erc20approvalgassponsor/types.go:100
Key returns the extension identifier.
func ResolveSigner(network string) Erc20ApprovalGasSponsoringSigner
Source: extensions/erc20approvalgassponsor/types.go:106
ResolveSigner returns the signer to use for a given network. SignerForNetwork takes precedence when configured.
type Erc20ApprovalGasSponsoringSigner
Source: extensions/erc20approvalgassponsor/types.go:78
Erc20ApprovalGasSponsoringSigner extends FacilitatorEvmSigner with multi-transaction execution. The signer owns the execution strategy (sequential, batched, or atomic bundling via Flashbots, multicall, or smart account batching).
type Erc20ApprovalGasSponsoringSigner interface {
evm.FacilitatorEvmSigner
SendTransactions(ctx context.Context, transactions []TransactionRequest) ([]string, error)
}Methods
evm.FacilitatorEvmSignerSendTransactions func(ctx context.Context, transactions []TransactionRequest) ([]string, error)
type Erc20ApprovalGasSponsoringSimulator
Source: extensions/erc20approvalgassponsor/types.go:85
Erc20ApprovalGasSponsoringSimulator is an optional extension of Erc20ApprovalGasSponsoringSigner with multi-transaction simulation. The signer owns the simulation strategy.
type Erc20ApprovalGasSponsoringSimulator interface {
Erc20ApprovalGasSponsoringSigner
SimulateTransactions(ctx context.Context, transactions []TransactionRequest) (bool, error)
}Methods
Erc20ApprovalGasSponsoringSignerSimulateTransactions func(ctx context.Context, transactions []TransactionRequest) (bool, error)
type Extension
Source: extensions/erc20approvalgassponsor/types.go:48
Extension represents the full extension object as it appears in PaymentRequired.extensions and PaymentPayload.extensions.
type Extension struct {
Info interface{} `json:"info"`
Schema map[string]interface{} `json:"schema"`
}Fields
Info interface{}`json:"info"`Schema map[string]interface{}`json:"schema"`
type Info
Source: extensions/erc20approvalgassponsor/types.go:24
Info contains the signed approve transaction data populated by the client. The facilitator broadcasts this transaction before calling settle().
type Info struct {
// From is the address of the sender (token owner).
From string `json:"from"`
// Asset is the address of the ERC-20 token contract.
Asset string `json:"asset"`
// Spender is the address being approved (Canonical Permit2).
Spender string `json:"spender"`
// Amount is the approval amount (uint256 as decimal string). Typically MaxUint256.
Amount string `json:"amount"`
// SignedTransaction is the RLP-encoded signed approve transaction as a hex string (0x-prefixed).
SignedTransaction string `json:"signedTransaction"`
// Version is the schema version identifier.
Version string `json:"version"`
}Fields
From string`json:"from"`From is the address of the sender (token owner).
Asset string`json:"asset"`Asset is the address of the ERC-20 token contract.
Spender string`json:"spender"`Spender is the address being approved (Canonical Permit2).
Amount string`json:"amount"`Amount is the approval amount (uint256 as decimal string). Typically MaxUint256.
SignedTransaction string`json:"signedTransaction"`SignedTransaction is the RLP-encoded signed approve transaction as a hex string (0x-prefixed).
Version string`json:"version"`Version is the schema version identifier.
type ServerInfo
Source: extensions/erc20approvalgassponsor/types.go:41
ServerInfo is the server-side info included in PaymentRequired. Contains a description and version; the client populates the rest.
type ServerInfo struct {
Description string `json:"description"`
Version string `json:"version"`
}Fields
Description string`json:"description"`Version string`json:"version"`
type TransactionRequest
Source: extensions/erc20approvalgassponsor/types.go:66
TransactionRequest represents a single transaction to be executed by the signer. Either Serialized (pre-signed raw transaction) or Call (unsigned intent) must be set.
type TransactionRequest struct {
// Serialized is a pre-signed raw transaction hex (0x-prefixed).
// When non-empty, the signer broadcasts it as-is via sendRawTransaction.
Serialized string
// Call is an unsigned contract write for the signer to sign and execute.
// Used when Serialized is empty.
Call *WriteContractCall
}Fields
Serialized stringSerialized is a pre-signed raw transaction hex (0x-prefixed). When non-empty, the signer broadcasts it as-is via sendRawTransaction.
Call *WriteContractCallCall is an unsigned contract write for the signer to sign and execute. Used when Serialized is empty.
type WriteContractCall
Source: extensions/erc20approvalgassponsor/types.go:55
WriteContractCall encapsulates arguments for a WriteContract call, used by SendTransactions to describe an unsigned contract call operation.
type WriteContractCall struct {
Address string
ABI []byte
Function string
Args []interface{}
// DataSuffix is appended to the ABI-encoded calldata when non-empty
DataSuffix []byte
}Fields
Address stringABI []byteFunction stringArgs []interface{}DataSuffix []byteDataSuffix is appended to the ABI-encoded calldata when non-empty
