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
impl AuthenticatedClient
Sourcepub fn new(
host: impl Into<String>,
signer: impl EthSigner + 'static,
chain_id: u64,
api_creds: Option<ApiCreds>,
funder: Option<Address>,
) -> Self
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 APIsigner- 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 operationsfunder- 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
Sourcepub fn api_creds(&self) -> Option<&ApiCreds>
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...
}Sourcepub fn set_api_creds(&mut self, api_creds: Option<ApiCreds>)
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()orderive_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?;Sourcepub async fn create_api_key(&self, nonce: Option<U256>) -> Result<ApiCreds>
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.
Sourcepub async fn derive_api_key(&self) -> Result<ApiCreds>
pub async fn derive_api_key(&self) -> Result<ApiCreds>
Derive API key from existing credentials (L1 authentication required)
Sourcepub async fn create_or_derive_api_key(&self) -> Result<ApiCreds>
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.
Sourcepub async fn get_api_keys(&self) -> Result<ApiKeysResponse>
pub async fn get_api_keys(&self) -> Result<ApiKeysResponse>
Get all API keys for the current user (L2 authentication required)
Sourcepub async fn delete_api_key(&self) -> Result<Value>
pub async fn delete_api_key(&self) -> Result<Value>
Delete an API key (L2 authentication required)
Sourcepub async fn get_balance_allowance(
&self,
params: BalanceAllowanceParams,
) -> Result<Value>
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
Sourcepub async fn update_balance_allowance(&self) -> Result<Value>
pub async fn update_balance_allowance(&self) -> Result<Value>
Update balance allowance (L2 authentication required)
Sourcepub async fn get_notifications(&self) -> Result<Value>
pub async fn get_notifications(&self) -> Result<Value>
Get notifications for the current user (L2 authentication required)
Sourcepub async fn drop_notifications(&self, ids: &[String]) -> Result<Value>
pub async fn drop_notifications(&self, ids: &[String]) -> Result<Value>
Drop (delete) notifications (L2 authentication required)
Sourcepub fn get_address(&self) -> String
pub fn get_address(&self) -> String
Get the signer’s address
Sourcepub fn get_funder(&self) -> Option<Address>
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§
impl Freeze for AuthenticatedClient
impl !RefUnwindSafe for AuthenticatedClient
impl Send for AuthenticatedClient
impl Sync for AuthenticatedClient
impl Unpin for AuthenticatedClient
impl !UnwindSafe for AuthenticatedClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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