Client

Struct Client 

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

OneMoney API client.

Implementations§

Source§

impl Client

Source

pub async fn get_account_nonce(&self, address: Address) -> Result<AccountNonce>

Get the nonce for an account.

§Arguments
  • address - The account address to query
§Returns

The account nonce information.

§Example
use onemoney_protocol::Client;
use alloy_primitives::Address;
use std::str::FromStr;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;
    let address = Address::from_str("0x742d35Cc6634C0532925a3b8D91D6F4A81B8Cbc0")?;

    let nonce = client.get_account_nonce(address).await?;
    println!("Account nonce: {}", nonce.nonce);

    Ok(())
}
Source

pub async fn get_associated_token_account( &self, address: Address, token: Address, ) -> Result<AssociatedTokenAccount>

Get associated token account information for a specific address and token.

This method queries the L1 server’s /v1/accounts/token_account endpoint to retrieve token account details including balance and nonce.

§Arguments
  • address - The wallet owner address
  • token - The token mint address
§Returns

The associated token account information.

§Example
use onemoney_protocol::Client;
use alloy_primitives::Address;
use std::str::FromStr;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;
    let address = Address::from_str("0x742d35Cc6634C0532925a3b8D91D6F4A81B8Cbc0")?;
    let token = Address::from_str("0x1234567890abcdef1234567890abcdef12345678")?;

    let account = client.get_associated_token_account(address, token).await?;
    println!("Token balance: {}", account.balance);

    Ok(())
}
Source§

impl Client

Source

pub async fn get_chain_id(&self) -> Result<u64>

Get the current chain ID.

§Returns

The chain ID.

§Example
use onemoney_protocol::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let chain_id = client.get_chain_id().await?;
    println!("Current chain ID: {}", chain_id);

    Ok(())
}
Source§

impl Client

Source

pub async fn get_checkpoint_by_number( &self, number: u64, full: bool, ) -> Result<Checkpoint>

Get a specific checkpoint by number.

§Arguments
  • number - The checkpoint number
  • full - Whether to include full transaction details
§Returns

The checkpoint information.

§Example
use onemoney_protocol::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let checkpoint = client.get_checkpoint_by_number(456, false).await?;
    println!("Checkpoint number: {}", checkpoint.number);

    Ok(())
}
Source

pub async fn get_checkpoint_by_hash( &self, hash: &str, full: bool, ) -> Result<Checkpoint>

Get a checkpoint by hash.

§Arguments
  • hash - The checkpoint hash
  • full - Whether to include full transaction details
§Returns

The checkpoint information.

§Example
use onemoney_protocol::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let hash = "0x902006665c369834a0cf52eea2780f934a90b3c86a3918fb57371ac1fbbd7777";
    let checkpoint = client.get_checkpoint_by_hash(hash, false).await?;
    println!("Checkpoint number: {}", checkpoint.number);

    Ok(())
}
Source

pub async fn get_checkpoint_number(&self) -> Result<CheckpointNumber>

Get the latest checkpoint number.

§Returns

The latest checkpoint number.

§Example
use onemoney_protocol::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let checkpoint_number = client.get_checkpoint_number().await?;
    println!("Latest checkpoint number: {}", checkpoint_number.number);

    Ok(())
}
Source§

impl Client

Source

pub async fn get_latest_epoch_checkpoint(&self) -> Result<LatestStateResponse>

Get the latest epoch and checkpoint information.

This is commonly used when creating transactions to get the required recent_epoch and recent_checkpoint values.

§Returns

The latest state information.

§Example
use onemoney_protocol::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let state = client.get_latest_epoch_checkpoint().await?;
    println!("Latest state: epoch {} checkpoint {}", state.epoch, state.checkpoint);

    // Use in transaction payload
    let recent_epoch = state.epoch;
    let recent_checkpoint = state.checkpoint;

    Ok(())
}
Source§

impl Client

Source

pub async fn mint_token( &self, payload: TokenMintPayload, private_key: &str, ) -> Result<TransactionResponse>

Mint tokens to an account.

§Arguments
  • payload - Token mint parameters
  • private_key - Private key for signing the transaction (must have mint authority)
§Returns

The transaction result.

Source

pub async fn burn_token( &self, payload: TokenBurnPayload, private_key: &str, ) -> Result<TransactionResponse>

Burn tokens from an account.

§Arguments
  • payload - Token burn parameters
  • private_key - Private key for signing the transaction (must have burn authority)
§Returns

The transaction result.

Source

pub async fn grant_authority( &self, payload: TokenAuthorityPayload, private_key: &str, ) -> Result<TransactionResponse>

Grant authority for a token to an address.

§Arguments
  • payload - Authority grant parameters
  • private_key - Private key for signing the transaction (must have master authority)
§Returns

The transaction result.

Source

pub async fn revoke_authority( &self, payload: TokenAuthorityPayload, private_key: &str, ) -> Result<TransactionResponse>

Revoke authority for a token from an address.

Note: This method uses the same /v1/tokens/grant_authority endpoint as grant_authority(), but with AuthorityAction::Revoke in the payload to indicate a revoke operation.

§Arguments
  • payload - Authority revoke parameters (with action set to AuthorityAction::Revoke)
  • private_key - Private key for signing the transaction (must have master authority)
§Returns

The transaction result.

Source

pub async fn get_token_metadata( &self, mint_address: Address, ) -> Result<MintInfo>

Get token metadata by mint address.

§Arguments
  • mint_address - The token mint address
§Returns

The token metadata.

§Example
use onemoney_protocol::Client;
use alloy_primitives::Address;
use std::str::FromStr;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;
    let mint = Address::from_str("0x1234567890abcdef1234567890abcdef12345678")?;

    let mint_info = client.get_token_metadata(mint).await?;
    println!("Token: {}", mint_info.symbol);

    Ok(())
}
Source

pub async fn pause_token( &self, payload: TokenPausePayload, private_key: &str, ) -> Result<TransactionResponse>

Pause or unpause a token.

§Arguments
  • payload - Token pause parameters
  • private_key - Private key for signing the transaction (must have pause authority)
§Returns

The transaction result.

Source

pub async fn manage_blacklist( &self, payload: TokenBlacklistPayload, private_key: &str, ) -> Result<TransactionResponse>

Manage token blacklist (add or remove addresses).

§Arguments
  • payload - Token blacklist management parameters
  • private_key - Private key for signing the transaction (must have manage list authority)
§Returns

The transaction result.

Source

pub async fn manage_whitelist( &self, payload: TokenWhitelistPayload, private_key: &str, ) -> Result<TransactionResponse>

Manage token whitelist (add or remove addresses).

§Arguments
  • payload - Token whitelist management parameters
  • private_key - Private key for signing the transaction (must have manage list authority)
§Returns

The transaction result.

Source

pub async fn update_token_metadata( &self, payload: TokenMetadataUpdatePayload, private_key: &str, ) -> Result<TransactionResponse>

Update token metadata.

§Arguments
  • payload - Token metadata update parameters
  • private_key - Private key for signing the transaction (must have update metadata authority)
§Returns

The transaction result.

Source§

impl Client

Source

pub async fn send_payment( &self, payload: PaymentPayload, private_key: &str, ) -> Result<TransactionResponse>

Send a payment transaction.

§Arguments
  • payload - Payment transaction parameters
  • private_key - Private key for signing the transaction
§Returns

The payment response containing the transaction hash.

§Example
use onemoney_protocol::{Client, PaymentPayload};
use alloy_primitives::{Address, U256};
use std::str::FromStr;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let payload = PaymentPayload {
        recent_epoch: 123,
        recent_checkpoint: 456,
        chain_id: 1212101,
        nonce: 0,
        recipient: Address::from_str("0x742d35Cc6634C0532925a3b8D91D6F4A81B8Cbc0")?,
        value: U256::from(1000000000000000000u64), // 1 token
        token: Address::from_str("0x1234567890abcdef1234567890abcdef12345678")?,
    };

    let private_key = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
    let result = client.send_payment(payload, private_key).await?;
    println!("Transaction hash: {}", result.hash);

    Ok(())
}
Source

pub async fn get_transaction_by_hash(&self, hash: &str) -> Result<Transaction>

Get transaction by hash.

§Arguments
  • hash - The transaction hash to query
§Returns

The transaction information.

§Example
use onemoney_protocol::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let tx_hash = "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890";
    let transaction = client.get_transaction_by_hash(tx_hash).await?;

    println!("Transaction hash: {}", transaction.hash);

    Ok(())
}
Source

pub async fn estimate_fee( &self, request: FeeEstimateRequest, ) -> Result<FeeEstimate>

Estimate fees for a transaction.

§Arguments
  • request - Fee estimation request parameters
§Returns

The fee estimate information.

§Example
use onemoney_protocol::{Client, FeeEstimateRequest};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let request = FeeEstimateRequest {
        from: "0x742d35Cc6634C0532925a3b8D91D6F4A81B8Cbc0".to_string(),
        value: "1000000000000000000".to_string(),
        token: None,
    };

    let estimate = client.estimate_fee(request).await?;
    println!("Estimated fee: {}", estimate.fee);

    Ok(())
}
Source

pub async fn get_transaction_receipt_by_hash( &self, hash: &str, ) -> Result<TransactionReceipt>

Get transaction receipt by hash.

§Arguments
  • hash - The transaction hash to query
§Returns

The transaction receipt information.

§Example
use onemoney_protocol::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::mainnet()?;

    let tx_hash = "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890";
    let receipt = client.get_transaction_receipt_by_hash(tx_hash).await?;

    println!("Transaction success: {}", receipt.success);
    println!("Fee used: {}", receipt.fee_used);

    Ok(())
}
Source§

impl Client

Source

pub fn mainnet() -> Result<Self>

Create a new client for mainnet.

Source

pub fn testnet() -> Result<Self>

Create a new client for testnet.

Source

pub fn local() -> Result<Self>

Create a new client for local development.

Source

pub async fn get<T>(&self, path: &str) -> Result<T>

Perform a GET request.

Source

pub async fn post<B, T>(&self, path: &str, body: &B) -> Result<T>

Perform a POST request.

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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> 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<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
Source§

impl<T> ErasedDestructor for T
where T: 'static,