Extensions

extensions/eip2612gassponsor

Package eip2612gassponsor provides types and helpers for the EIP-2612 Gas Sponsoring extension.

import "github.com/x402-foundation/x402/go/v2/extensions/eip2612gassponsor"

Package eip2612gassponsor provides types and helpers for the EIP-2612 Gas Sponsoring extension.

This extension enables gasless approval of the Permit2 contract for tokens that implement EIP-2612. The client signs an off-chain permit, and the facilitator submits it on-chain via x402Permit2Proxy.settleWithPermit.

Variables

EIP2612GasSponsoring is the extension identifier for the EIP-2612 gas sponsoring extension.

Source: extensions/eip2612gassponsor/types.go:11

var EIP2612GasSponsoring = x402.NewFacilitatorExtension("eip2612GasSponsoring")

Functions

func DeclareEip2612GasSponsoringExtension() map[string]interface{}

Source: extensions/eip2612gassponsor/server.go:16

DeclareEip2612GasSponsoringExtension creates the extension declaration for inclusion in PaymentRequired.extensions.

The server advertises that it (or its facilitator) supports EIP-2612 gasless Permit2 approval. The client will populate the info with the actual permit signature data.

Returns a map keyed by the extension identifier.

Example:

extensions := eip2612gassponsor.DeclareEip2612GasSponsoringExtension()
// Include in PaymentRequired.Extensions

func ExtractEip2612GasSponsoringInfo(extensions map[string]interface{}) (*Info, error)

Source: extensions/eip2612gassponsor/facilitator.go:14

ExtractEip2612GasSponsoringInfo extracts the EIP-2612 gas sponsoring info from a payment payload's extensions (raw JSON bytes).

Returns the info if the extension is present and contains the required client-populated fields, or nil if not present.

func ExtractEip2612GasSponsoringInfoFromPayloadBytes(payloadBytes []byte) (*Info, error)

Source: extensions/eip2612gassponsor/facilitator.go:58

ExtractEip2612GasSponsoringInfoFromPayloadBytes extracts the EIP-2612 gas sponsoring info from raw payment payload JSON bytes.

func ValidateEip2612GasSponsoringInfo(info *Info) bool

Source: extensions/eip2612gassponsor/facilitator.go:78

ValidateEip2612GasSponsoringInfo validates that the EIP-2612 gas sponsoring info has valid format.

Types

type Extension

Source: extensions/eip2612gassponsor/types.go:43

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/eip2612gassponsor/types.go:15

Info contains the EIP-2612 permit data populated by the client. The facilitator uses this to call settleWithPermit.

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 of the spender (Canonical Permit2).
	Spender string `json:"spender"`
	// Amount is the approval amount (uint256 as decimal string). Typically MaxUint256.
	Amount string `json:"amount"`
	// Nonce is the current EIP-2612 nonce of the sender (decimal string).
	Nonce string `json:"nonce"`
	// Deadline is the timestamp at which the permit signature expires (decimal string).
	Deadline string `json:"deadline"`
	// Signature is the 65-byte concatenated EIP-2612 permit signature (r, s, v) as hex.
	Signature string `json:"signature"`
	// 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 of the spender (Canonical Permit2).

  • Amount string `json:"amount"`

    Amount is the approval amount (uint256 as decimal string). Typically MaxUint256.

  • Nonce string `json:"nonce"`

    Nonce is the current EIP-2612 nonce of the sender (decimal string).

  • Deadline string `json:"deadline"`

    Deadline is the timestamp at which the permit signature expires (decimal string).

  • Signature string `json:"signature"`

    Signature is the 65-byte concatenated EIP-2612 permit signature (r, s, v) as hex.

  • Version string `json:"version"`

    Version is the schema version identifier.

type ServerInfo

Source: extensions/eip2612gassponsor/types.go:36

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"`