pub struct Account { /* private fields */ }Expand description
Unified account primitive for credential management and signing operations.
Account combines wallet (private key), API credentials, and signing capabilities
into a single abstraction. It provides factory methods for loading credentials from
various sources (environment variables, files) and handles both EIP-712 order signing
and HMAC-based L2 API authentication.
§Example
use polyte_clob::Account;
// Load from environment variables
let account = Account::from_env()?;
// Or load from a JSON file
let account = Account::from_file("config/account.json")?;
// Get the wallet address
println!("Address: {:?}", account.address());Implementations§
Source§impl Account
impl Account
Sourcepub fn new(
private_key: impl Into<String>,
credentials: Credentials,
) -> Result<Self>
pub fn new( private_key: impl Into<String>, credentials: Credentials, ) -> Result<Self>
Create a new account from private key and credentials.
§Arguments
private_key- Hex-encoded private key (with or without 0x prefix)credentials- API credentials for L2 authentication
§Example
use polyte_clob::{Account, Credentials};
let credentials = Credentials {
key: "api_key".to_string(),
secret: "api_secret".to_string(),
passphrase: "passphrase".to_string(),
};
let account = Account::new("0x...", credentials)?;Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Load account from environment variables.
Reads the following environment variables:
POLYMARKET_PRIVATE_KEY: Hex-encoded private keyPOLYMARKET_API_KEY: API keyPOLYMARKET_API_SECRET: API secret (base64 encoded)POLYMARKET_API_PASSPHRASE: API passphrase
§Example
use polyte_clob::Account;
let account = Account::from_env()?;Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self>
Load account from a JSON configuration file.
The file should contain:
{
"private_key": "0x...",
"key": "api_key",
"secret": "api_secret",
"passphrase": "passphrase"
}§Example
use polyte_clob::Account;
let account = Account::from_file("config/account.json")?;Sourcepub fn from_json(json: &str) -> Result<Self>
pub fn from_json(json: &str) -> Result<Self>
Load account from a JSON string.
§Example
use polyte_clob::Account;
let json = r#"{
"private_key": "0x...",
"key": "api_key",
"secret": "api_secret",
"passphrase": "passphrase"
}"#;
let account = Account::from_json(json)?;Sourcepub fn credentials(&self) -> &Credentials
pub fn credentials(&self) -> &Credentials
Get a reference to the credentials.
Sourcepub async fn sign_order(
&self,
order: &Order,
chain_id: u64,
) -> Result<SignedOrder>
pub async fn sign_order( &self, order: &Order, chain_id: u64, ) -> Result<SignedOrder>
Sign an order using EIP-712.
§Arguments
order- The unsigned order to signchain_id- The chain ID for EIP-712 domain
§Example
use polyte_clob::{Account, Order};
async fn example(account: &Account, order: &Order) -> Result<(), Box<dyn std::error::Error>> {
let signed_order = account.sign_order(order, 137).await?;
println!("Signature: {}", signed_order.signature);
Ok(())
}Sourcepub async fn sign_clob_auth(
&self,
chain_id: u64,
timestamp: u64,
nonce: u32,
) -> Result<String>
pub async fn sign_clob_auth( &self, chain_id: u64, timestamp: u64, nonce: u32, ) -> Result<String>
Sign a CLOB authentication message for API key creation (L1 auth).
§Arguments
chain_id- The chain ID for EIP-712 domaintimestamp- Unix timestamp in secondsnonce- Random nonce value
Sourcepub fn sign_l2_request(
&self,
timestamp: u64,
method: &str,
path: &str,
body: Option<&str>,
) -> Result<String>
pub fn sign_l2_request( &self, timestamp: u64, method: &str, path: &str, body: Option<&str>, ) -> Result<String>
Sign an L2 API request message using HMAC.
§Arguments
timestamp- Unix timestamp in secondsmethod- HTTP method (GET, POST, DELETE)path- Request path (e.g., “/order”)body- Optional request body
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Account
impl !RefUnwindSafe for Account
impl Send for Account
impl Sync for Account
impl Unpin for Account
impl !UnwindSafe for Account
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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