Signers

signers/evm

github.com/x402-foundation/x402/go/v2/signers/evm

import "github.com/x402-foundation/x402/go/v2/signers/evm"

Functions

func NewClientSignerFromPrivateKey(privateKeyHex string) (x402evm.ClientEvmSigner, error)

Source: signers/evm/client.go:50

NewClientSignerFromPrivateKey creates a client signer from a hex-encoded private key.

Args:

privateKeyHex: Hex-encoded private key (with or without "0x" prefix)

Returns:

ClientEvmSigner implementation ready for use with evm.NewExactEvmClient()
Error if private key is invalid

Example:

signer, err := evm.NewClientSignerFromPrivateKey("0x1234...")
if err != nil {
    log.Fatal(err)
}
client := x402.Newx402Client().
    Register("eip155:*", evm.NewExactEvmClient(signer))

func NewClientSignerFromPrivateKeyWithClient(privateKeyHex string, ethClient *ethclient.Client) (x402evm.ClientEvmSigner, error)

Source: signers/evm/client.go:58

NewClientSignerFromPrivateKeyWithClient creates a client signer from a private key and an optional ethclient for contract reads (e.g., querying EIP-2612 nonces).

If ethClient is nil, ReadContract will return an error when called.

Types

type ClientSigner

Source: signers/evm/client.go:25

ClientSigner implements x402evm.ClientEvmSigner using an ECDSA private key. This provides client-side EIP-712 signing for creating payment payloads.

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

func Address() string

Source: signers/evm/client.go:79

Address returns the Ethereum address of the signer.

func EstimateFeesPerGas(ctx context.Context) (maxFeePerGas, maxPriorityFeePerGas *big.Int, err error)

Source: signers/evm/client.go:211

EstimateFeesPerGas returns EIP-1559 fee parameters by querying the connected node. Returns maxFeePerGas and maxPriorityFeePerGas. Falls back to 1 gwei / 0.1 gwei on error. Requires an ethclient to be provided via NewClientSignerFromPrivateKeyWithClient.

func GetTransactionCount(ctx context.Context, address string) (uint64, error)

Source: signers/evm/client.go:197

GetTransactionCount returns the pending nonce for the given address. Requires an ethclient to be provided via NewClientSignerFromPrivateKeyWithClient.

func HasRPCClient() bool

Source: signers/evm/client.go:265

HasRPCClient reports whether the signer is backed by an ethclient. When false, its RPC-dependent methods (ReadContract, GetTransactionCount) are non-functional, so callers such as evm.ResolveReadSigner fall back to a scheme-configured RPC URL.

func ReadContract( ctx context.Context, contractAddress string, abiBytes []byte, functionName string, args ...interface{}, ) (interface{}, error)

Source: signers/evm/client.go:271

ReadContract reads data from a smart contract. Requires an ethclient to be provided via NewClientSignerFromPrivateKeyWithClient.

func SignMessage(_ context.Context, message string) (string, error)

Source: signers/evm/client.go:84

SignMessage signs a UTF-8 message using the EIP-191 personal-sign format.

func SignTransaction(ctx context.Context, tx *types.Transaction) ([]byte, error)

Source: signers/evm/client.go:244

SignTransaction signs an EIP-1559 transaction using the signer's private key and returns the RLP-encoded signed transaction bytes.

func SignTypedData( ctx context.Context, domain x402evm.TypedDataDomain, types map[string][]x402evm.TypedDataField, primaryType string, message map[string]interface{}, ) ([]byte, error)

Source: signers/evm/client.go:107

SignTypedData signs EIP-712 typed data.

Args:

ctx: Context for cancellation and timeout control
domain: EIP-712 domain separator
types: Type definitions for the structured data
primaryType: The primary type being signed
message: The message data to sign

Returns:

65-byte signature (r, s, v)
Error if signing fails