Mechanisms

mechanisms/evm/exact/client

github.com/x402-foundation/x402/go/v2/mechanisms/evm/exact/client

import "github.com/x402-foundation/x402/go/v2/mechanisms/evm/exact/client"

Constants

Client error constants for the exact EVM scheme (V2)

Source: mechanisms/evm/exact/client/errors.go:5

const (
	ErrInvalidAmount                    = "invalid_exact_evm_client_amount"
	ErrFailedToSignAuthorization        = "invalid_exact_evm_client_failed_to_sign_authorization"
	ErrFailedToSignPermit2Authorization = "invalid_exact_evm_client_failed_to_sign_permit2_authorization"
)

Functions

func CreatePermit2ApprovalTxData(tokenAddress string) (to string, abi []byte, functionName string, args []interface{})

Source: mechanisms/evm/exact/client/permit2.go:145

CreatePermit2ApprovalTxData creates transaction data to approve Permit2 to spend tokens. The user sends this transaction (paying gas) before using Permit2 flow. Returns the target address and calldata.

func CreatePermit2Payload( ctx context.Context, signer evm.ClientEvmSigner, requirements types.PaymentRequirements, ) (types.PaymentPayload, error)

Source: mechanisms/evm/exact/client/permit2.go:16

CreatePermit2Payload creates a Permit2 payload using the x402Permit2Proxy witness pattern. The spender is set to x402Permit2Proxy, which enforces that funds can only be sent to the witness.to address.

func GetPermit2AllowanceReadParams(params Permit2AllowanceParams) (address string, abi []byte, functionName string, args []interface{})

Source: mechanisms/evm/exact/client/permit2.go:135

GetPermit2AllowanceReadParams returns contract read parameters for checking Permit2 allowance. Use with a signer's ReadContract method to check if the user has approved Permit2.

func NewExactEvmScheme(signer evm.ClientEvmSigner, config *ExactEvmSchemeConfig) *ExactEvmScheme

Source: mechanisms/evm/exact/client/scheme.go:26

NewExactEvmScheme creates a new ExactEvmScheme. Base flows only require a signer that can sign typed data. Extension enrichment paths use optional runtime capabilities.

func SignEip2612Permit( ctx context.Context, signer evm.ClientEvmSignerWithReadContract, tokenAddress string, tokenName string, tokenVersion string, chainID *big.Int, deadline string, permittedAmount string, ) (*eip2612gassponsor.Info, error)

Source: mechanisms/evm/exact/client/eip2612.go:20

SignEip2612Permit signs an EIP-2612 permit authorizing the Permit2 contract to spend tokens. This creates a gasless off-chain signature that the facilitator can submit on-chain via x402Permit2Proxy.settleWithPermit().

The permittedAmount must match the Permit2 permitted.amount exactly, as the proxy contract enforces permit2612.value == permittedAmount.

func SignErc20ApprovalTransaction( ctx context.Context, signer evm.ClientEvmSignerWithTxSigning, tokenAddress string, chainID *big.Int, ) (*erc20approvalgassponsor.Info, error)

Source: mechanisms/evm/exact/client/erc20_approval.go:23

SignErc20ApprovalTransaction creates a signed (but unbroadcast) EIP-1559 transaction that calls approve(Permit2, MaxUint256) on the given ERC-20 token.

The returned Info contains the RLP-encoded signed transaction which the facilitator will broadcast before calling settle().

Types

type ExactEvmChainConfig

Source: mechanisms/evm/exact/client/rpc.go:10

ExactEvmChainConfig configures RPC behavior for one chain.

type ExactEvmChainConfig = evm.RPCChainConfig

type ExactEvmScheme

Source: mechanisms/evm/exact/client/scheme.go:18

ExactEvmScheme implements the SchemeNetworkClient interface for EVM exact payments (V2)

type ExactEvmScheme struct {
	// contains filtered or unexported fields
}

func CreatePaymentPayload( ctx context.Context, requirements types.PaymentRequirements, ) (types.PaymentPayload, error)

Source: mechanisms/evm/exact/client/scheme.go:41

CreatePaymentPayload creates a V2 payment payload for the exact scheme. Routes to EIP-3009 or Permit2 based on requirements.Extra["assetTransferMethod"]. Defaults to EIP-3009 for backward compatibility.

func CreatePaymentPayloadWithExtensions( ctx context.Context, requirements types.PaymentRequirements, extensions map[string]interface{}, ) (types.PaymentPayload, error)

Source: mechanisms/evm/exact/client/scheme.go:61

CreatePaymentPayloadWithExtensions creates a payment payload with extension awareness. For Permit2 flows, if the server advertises eip2612GasSponsoring and the signer supports ReadContract, automatically signs an EIP-2612 permit when Permit2 allowance is insufficient.

func Scheme) Scheme() string

Source: mechanisms/evm/exact/client/scheme.go:34

Scheme returns the scheme identifier

type ExactEvmSchemeConfig

Source: mechanisms/evm/exact/client/rpc.go:14

ExactEvmSchemeConfig configures RPC behavior for Exact EVM clients. If both RPCByChainID and RPCURL are set, chain-specific entries take precedence.

type ExactEvmSchemeConfig = evm.RPCConfig

type Permit2AllowanceParams

Source: mechanisms/evm/exact/client/permit2.go:128

Permit2AllowanceParams contains parameters for checking Permit2 allowance.

type Permit2AllowanceParams struct {
	TokenAddress string
	OwnerAddress string
}
Fields
  • TokenAddress string
  • OwnerAddress string