Skip to main content

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 std::str::FromStr;

use alloy_primitives::Address;
use onemoney_protocol::Client;

#[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_account_bbonce( &self, address: Address, ) -> Result<AccountBBNonce>

Get the BB nonce for an account.

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

The account BB nonce information.

§Example
use std::str::FromStr;

use alloy_primitives::Address;
use onemoney_protocol::Client;

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

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

    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 std::str::FromStr;

use alloy_primitives::Address;
use onemoney_protocol::Client;

#[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 const fn chain_id(&self) -> Option<ChainId>

Get the predefined chain ID for this network.

This method returns the predefined chain ID for the client’s network configuration without making any network requests. This is fast and always available.

§Returns

The predefined chain ID for this network or None for custom chains.

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

let client = Client::mainnet().unwrap();
let chain_id = client.chain_id();
assert_eq!(chain_id, NamedChain::MAINNET_CHAIN_ID);
Source

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

Fetch the current chain ID from the network API.

This method makes an HTTP request to fetch the chain ID from the network. Use this to verify that the network is responding correctly and matches the expected chain ID.

§Returns

The chain ID from the API response.

§Example
use onemoney_protocol::Client;

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

    let api_chain_id = client.fetch_chain_id_from_network().await?;
    let expected_chain_id = client.predefined_chain_id();

    assert_eq!(api_chain_id, expected_chain_id);
    println!("Network chain ID matches expected: {}", api_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_current_epoch(&self) -> Result<EpochResponse>

Fetch the current epoch information from the network.

§Returns

The latest epoch metadata including the governance certificate data.

§Example
let client = Client::testnet()?;
let epoch = client.get_current_epoch().await?;
println!("Current epoch id: {}", epoch.epoch_id);
Source

pub async fn get_epoch_by_id(&self, epoch_id: u64) -> Result<EpochResponse>

Fetch epoch information by its identifier.

§Arguments
  • epoch_id - The epoch identifier to query.
Source§

impl Client

Source

pub fn create_multisig_account_payload( &self, signers: &[SignerConfig], threshold: &ThresholdConfig, chain_id: u64, nonce: u64, ) -> Result<(Address, CreateMultiSigPayload)>

Create a multi-signature account transaction payload.

This method derives the multi-sig account address and creates the payload. The caller must sign this payload and submit via the standard transaction API.

§Arguments
  • signers - List of authorized signers with their weights
  • threshold - Minimum total weight required for transaction approval
  • chain_id - Chain ID for the transaction
  • nonce - Transaction nonce (get from account state)
§Returns

Tuple of (multi-sig account address, unsigned transaction payload)

§Errors

Returns error if signer configuration is invalid (e.g., threshold exceeds total weight)

§Example
use onemoney_protocol::{
    Client,
    NamedChain
    utils::{SignerConfig, ThresholdConfig},
};

let client = Client::testnet()?;

let signer1 = SignerConfig::new(vec![2; 33], 1)?;
let signer2 = SignerConfig::new(vec![3; 33], 1)?;
let threshold = ThresholdConfig::new(2)?;

let (_multisig_address, payload) = client.create_multisig_account_payload(
    &[signer1, signer2],
    &threshold,
    NamedChain::MAINNET_CHAIN_ID, // chain_id
    0,     // nonce
)?;

println!("Payload created: {:?}", payload);
Source

pub async fn submit_create_multisig_account( &self, signers: &[SignerConfig], threshold: &ThresholdConfig, chain_id: u64, nonce: u64, private_key: &str, ) -> Result<(Address, TransactionResponse)>

Create and submit a multi-signature account creation transaction.

This is a convenience method that creates the payload, signs it, and submits it.

§Arguments
  • signers - List of authorized signers with their weights
  • threshold - Minimum total weight required for transaction approval
  • chain_id - Chain ID for the transaction
  • nonce - Transaction nonce (get from creator’s account state)
  • private_key - Creator’s private key (pays for account creation)
§Returns

Tuple of (multi-sig account address, transaction hash)

Source

pub async fn submit_multisig_payment_transaction( &self, payload: PaymentPayload, multisig_account: Address, signatures: Vec<MultiSigSignatureEntry>, ) -> Result<TransactionResponse>

Submit a multi-signature payment transaction.

This method assumes signatures have already been collected off-chain.

Source

pub async fn submit_multisig_token_issue_transaction( &self, payload: TokenIssuePayload, multisig_account: Address, signatures: Vec<MultiSigSignatureEntry>, ) -> Result<TransactionResponse>

Submit a multi-signature token issue transaction.

This method assumes signatures have already been collected off-chain.

Source

pub async fn submit_multisig_token_mint_transaction( &self, payload: TokenMintPayload, multisig_account: Address, signatures: Vec<MultiSigSignatureEntry>, ) -> Result<TransactionResponse>

Submit a multi-signature token mint transaction.

This method assumes signatures have already been collected off-chain.

Source

pub fn create_multisig_payment_payload( &self, recipient: Address, token: Address, amount: U256, chain_id: u64, nonce: u64, ) -> PaymentPayload

Create a multi-signature payment transaction.

This helper creates a payment transaction payload that needs to be signed by multiple signers of a multi-sig account.

§Workflow
  1. Create payment payload with this method
  2. Each signer signs the payload independently (offline signing supported)
  3. Collect signatures using MultiSigSignatureCollector
  4. Create signed transaction with Signed::new_multi_sig()
  5. Submit transaction
§Arguments
  • recipient - Recipient address
  • token - Token mint address
  • amount - Amount to send
  • chain_id - Chain ID
  • nonce - Multi-sig account’s nonce
§Returns

Unsigned payment payload ready for signing

§Example
use alloy_primitives::{Address, U256};
use onemoney_protocol::{
    Client, NamedChain, crypto::sign_multisig_transaction_payload,
    utils::MultiSigSignatureCollector,
};

let client = Client::testnet()?;

// Create payment payload
let multisig_account = Address::ZERO; // Your multi-sig account
let recipient = Address::ZERO;
let payload = client.create_multisig_payment_payload(
    recipient,
    Address::repeat_byte(1),
    U256::from(1000),
    NamedChain::MAINNET_CHAIN_ID, // chain_id
    5,                            // nonce
);

// Collect signatures from signers
let mut collector = MultiSigSignatureCollector::new();

// Signer 1 signs (can be offline)
let sig1 =
    sign_multisig_transaction_payload(&payload, multisig_account, "signer1_private_key")?;
collector.add_signature(signer1_pubkey, sig1);

// Signer 2 signs (can be offline)
let sig2 =
    sign_multisig_transaction_payload(&payload, multisig_account, "signer2_private_key")?;
collector.add_signature(signer2_pubkey, sig2);

// Create multi-sig transaction
let signatures = collector.signatures();
let signed_tx = om_primitives_types::transaction::Signed::new_multi_sig(
    payload,
    multisig_account,
    signatures,
);

// Submit via RawTransactionEnvelope::Payment...
Source§

impl Client

Source

pub async fn mint_token( &self, data: 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, data: 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, data: 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, data: 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 std::str::FromStr;

use alloy_primitives::Address;
use onemoney_protocol::Client;

#[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, data: 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, data: 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, data: 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, data: 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, data: 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 std::str::FromStr;

use alloy_primitives::{Address, U256};
use onemoney_protocol::{Client, NamedChain, PaymentPayload};

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

    let payload = PaymentPayload {
        chain_id: NamedChain::TESTNET_CHAIN_ID,
        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 submit_raw_transaction( &self, envelope: RawTransactionEnvelope, ) -> Result<TransactionResponse>

Submit a raw transaction envelope.

This is used for advanced transaction types such as multi-sig creation and multi-sig payments.

Source

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

Get transaction by hash.

§Arguments
  • hash - Transaction hash
§Returns

The transaction details.

Source

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

Get transaction receipt by hash.

§Arguments
  • hash - Transaction hash
§Returns

The transaction receipt.

Source

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

Wait for a transaction receipt using the default timeout.

This method polls the receipt endpoint every 50ms for up to 30 seconds.

Source

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

Wait for a transaction receipt with a custom timeout.

§Arguments
  • hash - Transaction hash
  • timeout - Maximum duration to poll before returning a timeout error
Source

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

Estimate transaction fee.

§Arguments
  • request - Fee estimation parameters
§Returns

The estimated fee.

Source

pub async fn get_finalized_transaction_by_hash( &self, hash: &str, ) -> Result<FinalizedTransaction>

Get finalized transaction and receipt by hash.

§Arguments
  • hash - Transaction hash
§Returns

The finalized transaction and receipt.

Source

pub async fn get_and_verify_finalized_transaction_by_hash( &self, hash: &str, ) -> Result<FinalizedTransaction>

Get and verify finalized transaction by hash with BLS signature verification.

This is a convenience method that fetches the finalized transaction and automatically verifies the BLS aggregate signature from validators.

§Arguments
  • hash - Transaction hash (with or without 0x prefix)
§Returns

The finalized transaction if signature verification passes, error otherwise.

§Example
use onemoney_protocol::Client;

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

    // This will fetch AND verify the transaction
    let finalized_tx = client
        .get_and_verify_finalized_transaction_by_hash("0x1234...")
        .await?;

    println!("Transaction verified! Epoch: {}", finalized_tx.epoch);
    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 fn custom(base_url: String) -> Result<Self>

Create a new client for custom network.

Source

pub fn base_url(&self) -> &Url

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