AuthenticatedClient

Struct AuthenticatedClient 

Source
pub struct AuthenticatedClient { /* private fields */ }
Expand description

Client for authenticated operations

This client handles operations that require authentication, such as API key management and account queries.

For PolyProxy wallets, the signer is used for API authentication while the funder address is used as the order maker.

Implementations§

Source§

impl AuthenticatedClient

Source

pub fn new( host: impl Into<String>, signer: impl EthSigner + 'static, chain_id: u64, api_creds: Option<ApiCreds>, funder: Option<Address>, ) -> Self

Create a new AuthenticatedClient

§Arguments
  • host - The base URL for the API
  • signer - The Ethereum signer (used for API authentication)
  • chain_id - The chain ID (137 for Polygon, 80002 for Amoy testnet)
  • api_creds - Optional API credentials for L2 operations
  • funder - Optional funder address (for PolyProxy wallets, this is the proxy wallet address)
§PolyProxy Wallets

For PolyProxy wallets:

  • signer: Your EOA private key (delegated signer)
  • funder: Your proxy wallet address (holds the funds)
  • API authentication uses the signer address
  • Orders are made by the funder address
Source

pub fn api_creds(&self) -> Option<&ApiCreds>

Get the API credentials if available

Returns a reference to the API credentials if they were provided when creating the client. This is useful for accessing credentials for WebSocket authentication.

§Example
let auth_client = AuthenticatedClient::new(
    "https://clob.polymarket.com",
    signer,
    137,
    Some(creds),
    None,
);

// Use the credentials for WebSocket authentication
if let Some(creds) = auth_client.api_creds() {
    let ws_client = UserWsClient::new();
    let mut stream = ws_client.subscribe_with_creds(creds).await?;
    // Process events...
}
Source

pub fn set_api_creds(&mut self, api_creds: Option<ApiCreds>)

Set the API credentials

Updates the API credentials for this client. This is useful when you want to:

  • Initialize the client without credentials
  • Fetch credentials later using create_api_key() or derive_api_key()
  • Update credentials without recreating the client
§Example
// Create client without credentials
let mut auth_client = AuthenticatedClient::new(
    "https://clob.polymarket.com",
    signer,
    137,
    None,  // No credentials initially
    None,
);

// Fetch credentials using L1 authentication
let creds = auth_client.create_or_derive_api_key().await?;

// Set the credentials
auth_client.set_api_creds(Some(creds));

// Now you can use L2 authenticated methods
let keys = auth_client.get_api_keys().await?;
Source

pub async fn create_api_key(&self, nonce: Option<U256>) -> Result<ApiCreds>

Create a new API key (L1 authentication required)

This creates a new API key for the signer’s address. Requires wallet signature.

Source

pub async fn derive_api_key(&self) -> Result<ApiCreds>

Derive API key from existing credentials (L1 authentication required)

Source

pub async fn create_or_derive_api_key(&self) -> Result<ApiCreds>

Create or derive API key with fallback

Tries to create a new API key, falls back to derive if creation fails.

Source

pub async fn get_api_keys(&self) -> Result<ApiKeysResponse>

Get all API keys for the current user (L2 authentication required)

Source

pub async fn delete_api_key(&self) -> Result<Value>

Delete an API key (L2 authentication required)

Source

pub async fn get_balance_allowance( &self, params: BalanceAllowanceParams, ) -> Result<Value>

Get balance and allowance information (L2 authentication required)

§Arguments
  • params - Query parameters for balance/allowance
Source

pub async fn update_balance_allowance(&self) -> Result<Value>

Update balance allowance (L2 authentication required)

Source

pub async fn get_notifications(&self) -> Result<Value>

Get notifications for the current user (L2 authentication required)

Source

pub async fn drop_notifications(&self, ids: &[String]) -> Result<Value>

Drop (delete) notifications (L2 authentication required)

Source

pub fn get_address(&self) -> String

Get the signer’s address

Source

pub fn get_funder(&self) -> Option<Address>

Get the funder address (for PolyProxy wallets)

Returns the proxy wallet address if set, otherwise None. For EOA wallets, this should return None.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more