Documentation
¶
Overview ¶
Package buyer produces http.Client that can make x402 payments for HTTP content and services.
It is anticipated that this software will commonly be used to allow AI agents to pay for the services they need. When allowing automated payments on your behalf, care should be taken to limit your financial exposure.
Defaults
- If the WithClient option is not specified, the http.DefaultClient is used with the http.DefaultTransport.
- If the WithLogger Option is not specified, a No-Op logger is used.
Index ¶
- func ClientForKeyStore(ks *keystore.KeyStore, acct accounts.Account, pass []byte, opts ...Option) (*http.Client, error)
- func ClientForPrivateKey(priv *ecdsa.PrivateKey, opts ...Option) (*http.Client, error)
- func ClientForPrivateKeyHex(privHex string, opts ...Option) (*http.Client, error)
- func ClientForPrivateKeyHexFromEnv(name string, opts ...Option) (*http.Client, error)
- func ClientForSigner(signer api.Signer, opts ...Option) (*http.Client, error)
- type Option
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientForKeyStore ¶ added in v0.3.0
func ClientForKeyStore(ks *keystore.KeyStore, acct accounts.Account, pass []byte, opts ...Option) (*http.Client, error)
ClientForKeyStore returns an http.Client capable of making payments using cryptocurrency from an Ethereum account in an Ethereum keystore.
func ClientForPrivateKey ¶
ClientForPrivateKey returns an http.Client capable of making payments using cryptocurrency from the Ethereum account associated with the provided ECDSA private key (which is expected to be using the Ethereum secp256k1 curve.)
func ClientForPrivateKeyHex ¶
ClientForPrivateKeyHex is like ClientForPrivateKey except that the private key is parsed from the provided hexadecimal string.
func ClientForPrivateKeyHexFromEnv ¶
ClientForPrivateKeyHexFromEnv is like ClientForPrivateKeyHex except that hexadecimal string is read from the environment variable selected by name.
Types ¶
type Option ¶
type Option func(*config) error
Option represents a means of altering the default configuration of the buyer's http.RoundTripper.
func WithClient ¶
WithClient is an Option that allows the user to provide a custom http.Client whose http.RoundTripper will be wrapped to allow x402 payments.
If not provided, http.DefaultClient will be used and internally, the http.DefaultTransport will be wrapped with the payment middleware. This option is ignored when provided as an argument to NewTransport.
func WithLogger ¶
WithLogger is an Option that allows the user to provide an slog.Logger that can be used to observe the internal operation of the buyer's http.RoundTripper.
If not provided, a No-Op logger is used. Under normal operation, this library writes one line of INFO-level logging for each payment that's made. Debug- level logging provides a log record for each step in the payment process.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is an http.RoundTripper that is capable of making x402 payments to access HTTP-based content or services on the Internet.
func NewTransport ¶
NewTransport creates an http.RoundTripper that is capable of making x402 payments using the provided api.Signer by wrapping the underlying http.Transport provided by the next argument.