pub struct Client { /* private fields */ }Expand description
OneMoney API client.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn get_account_nonce(&self, address: Address) -> Result<AccountNonce>
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(())
}Sourcepub async fn get_account_bbonce(
&self,
address: Address,
) -> Result<AccountBBNonce>
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(())
}Sourcepub async fn get_associated_token_account(
&self,
address: Address,
token: Address,
) -> Result<AssociatedTokenAccount>
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 addresstoken- 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
impl Client
Sourcepub const fn chain_id(&self) -> Option<ChainId>
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);Sourcepub async fn fetch_chain_id_from_network(&self) -> Result<u64>
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
impl Client
Sourcepub async fn get_checkpoint_by_number(
&self,
number: u64,
full: bool,
) -> Result<Checkpoint>
pub async fn get_checkpoint_by_number( &self, number: u64, full: bool, ) -> Result<Checkpoint>
Get a specific checkpoint by number.
§Arguments
number- The checkpoint numberfull- 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(())
}Sourcepub async fn get_checkpoint_by_hash(
&self,
hash: &str,
full: bool,
) -> Result<Checkpoint>
pub async fn get_checkpoint_by_hash( &self, hash: &str, full: bool, ) -> Result<Checkpoint>
Get a checkpoint by hash.
§Arguments
hash- The checkpoint hashfull- 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(())
}Sourcepub async fn get_checkpoint_number(&self) -> Result<CheckpointNumber>
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
impl Client
Sourcepub async fn get_current_epoch(&self) -> Result<EpochResponse>
pub async fn get_current_epoch(&self) -> Result<EpochResponse>
Sourcepub async fn get_epoch_by_id(&self, epoch_id: u64) -> Result<EpochResponse>
pub async fn get_epoch_by_id(&self, epoch_id: u64) -> Result<EpochResponse>
Source§impl Client
impl Client
Sourcepub fn create_multisig_account_payload(
&self,
signers: &[SignerConfig],
threshold: &ThresholdConfig,
chain_id: u64,
nonce: u64,
) -> Result<(Address, CreateMultiSigPayload)>
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 weightsthreshold- Minimum total weight required for transaction approvalchain_id- Chain ID for the transactionnonce- 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);Sourcepub async fn submit_create_multisig_account(
&self,
signers: &[SignerConfig],
threshold: &ThresholdConfig,
chain_id: u64,
nonce: u64,
private_key: &str,
) -> Result<(Address, TransactionResponse)>
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 weightsthreshold- Minimum total weight required for transaction approvalchain_id- Chain ID for the transactionnonce- 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)
Sourcepub async fn submit_multisig_payment_transaction(
&self,
payload: PaymentPayload,
multisig_account: Address,
signatures: Vec<MultiSigSignatureEntry>,
) -> Result<TransactionResponse>
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.
Sourcepub async fn submit_multisig_token_issue_transaction(
&self,
payload: TokenIssuePayload,
multisig_account: Address,
signatures: Vec<MultiSigSignatureEntry>,
) -> Result<TransactionResponse>
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.
Sourcepub async fn submit_multisig_token_mint_transaction(
&self,
payload: TokenMintPayload,
multisig_account: Address,
signatures: Vec<MultiSigSignatureEntry>,
) -> Result<TransactionResponse>
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.
Sourcepub fn create_multisig_payment_payload(
&self,
recipient: Address,
token: Address,
amount: U256,
chain_id: u64,
nonce: u64,
) -> PaymentPayload
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
- Create payment payload with this method
- Each signer signs the payload independently (offline signing supported)
- Collect signatures using
MultiSigSignatureCollector - Create signed transaction with
Signed::new_multi_sig() - Submit transaction
§Arguments
recipient- Recipient addresstoken- Token mint addressamount- Amount to sendchain_id- Chain IDnonce- 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
impl Client
Sourcepub async fn mint_token(
&self,
data: TokenMintPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn mint_token( &self, data: TokenMintPayload, private_key: &str, ) -> Result<TransactionResponse>
Sourcepub async fn burn_token(
&self,
data: TokenBurnPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn burn_token( &self, data: TokenBurnPayload, 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.
Sourcepub async fn get_token_metadata(
&self,
mint_address: Address,
) -> Result<MintInfo>
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(())
}Sourcepub async fn pause_token(
&self,
data: TokenPausePayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn pause_token( &self, data: TokenPausePayload, private_key: &str, ) -> Result<TransactionResponse>
Sourcepub async fn manage_blacklist(
&self,
data: TokenBlacklistPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn manage_blacklist( &self, data: TokenBlacklistPayload, private_key: &str, ) -> Result<TransactionResponse>
Sourcepub async fn manage_whitelist(
&self,
data: TokenWhitelistPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn manage_whitelist( &self, data: TokenWhitelistPayload, private_key: &str, ) -> Result<TransactionResponse>
Sourcepub async fn update_token_metadata(
&self,
data: TokenMetadataUpdatePayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn update_token_metadata( &self, data: TokenMetadataUpdatePayload, private_key: &str, ) -> Result<TransactionResponse>
Source§impl Client
impl Client
Sourcepub async fn send_payment(
&self,
data: PaymentPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn send_payment( &self, data: PaymentPayload, private_key: &str, ) -> Result<TransactionResponse>
Send a payment transaction.
§Arguments
payload- Payment transaction parametersprivate_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(())
}Sourcepub async fn submit_raw_transaction(
&self,
envelope: RawTransactionEnvelope,
) -> Result<TransactionResponse>
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.
Sourcepub async fn get_transaction_by_hash(&self, hash: &str) -> Result<Transaction>
pub async fn get_transaction_by_hash(&self, hash: &str) -> Result<Transaction>
Sourcepub async fn get_transaction_receipt_by_hash(
&self,
hash: &str,
) -> Result<TransactionReceipt>
pub async fn get_transaction_receipt_by_hash( &self, hash: &str, ) -> Result<TransactionReceipt>
Sourcepub async fn wait_for_transaction_receipt(
&self,
hash: &str,
) -> Result<TransactionReceipt>
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.
Sourcepub async fn wait_for_transaction_receipt_with_timeout(
&self,
hash: &str,
timeout: Duration,
) -> Result<TransactionReceipt>
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 hashtimeout- Maximum duration to poll before returning a timeout error
Sourcepub async fn estimate_fee(
&self,
request: FeeEstimateRequest,
) -> Result<FeeEstimate>
pub async fn estimate_fee( &self, request: FeeEstimateRequest, ) -> Result<FeeEstimate>
Sourcepub async fn get_finalized_transaction_by_hash(
&self,
hash: &str,
) -> Result<FinalizedTransaction>
pub async fn get_finalized_transaction_by_hash( &self, hash: &str, ) -> Result<FinalizedTransaction>
Sourcepub async fn get_and_verify_finalized_transaction_by_hash(
&self,
hash: &str,
) -> Result<FinalizedTransaction>
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(())
}Trait Implementations§
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> 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