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 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(())
}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 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
impl Client
Sourcepub fn get_chain_id(&self) -> u64
pub fn get_chain_id(&self) -> u64
Get the 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 chain ID for this network.
§Example
use onemoney_protocol::Client;
let client = Client::mainnet().unwrap();
let chain_id = client.get_chain_id();
assert_eq!(chain_id, 21210);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.get_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_latest_epoch_checkpoint(&self) -> Result<LatestStateResponse>
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
impl Client
Sourcepub async fn mint_token(
&self,
payload: TokenMintPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn mint_token( &self, payload: TokenMintPayload, private_key: &str, ) -> Result<TransactionResponse>
Sourcepub async fn burn_token(
&self,
payload: TokenBurnPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn burn_token( &self, payload: 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 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(())
}Sourcepub async fn pause_token(
&self,
payload: TokenPausePayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn pause_token( &self, payload: TokenPausePayload, private_key: &str, ) -> Result<TransactionResponse>
Sourcepub async fn manage_blacklist(
&self,
payload: TokenBlacklistPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn manage_blacklist( &self, payload: TokenBlacklistPayload, private_key: &str, ) -> Result<TransactionResponse>
Sourcepub async fn manage_whitelist(
&self,
payload: TokenWhitelistPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn manage_whitelist( &self, payload: TokenWhitelistPayload, private_key: &str, ) -> Result<TransactionResponse>
Sourcepub async fn update_token_metadata(
&self,
payload: TokenMetadataUpdatePayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn update_token_metadata( &self, payload: TokenMetadataUpdatePayload, private_key: &str, ) -> Result<TransactionResponse>
Source§impl Client
impl Client
Sourcepub async fn send_payment(
&self,
payload: PaymentPayload,
private_key: &str,
) -> Result<TransactionResponse>
pub async fn send_payment( &self, payload: 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 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(())
}Sourcepub async fn get_transaction_by_hash(&self, hash: &str) -> Result<Transaction>
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(())
}Sourcepub async fn estimate_fee(
&self,
request: FeeEstimateRequest,
) -> Result<FeeEstimate>
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(())
}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>
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(())
}