Formatting Functions
Formatting functions of Azoth SDK for working with numbers and blockchain data
formatInput()
formatInput()Converts a human-readable amount into a bigint for use in blockchain transactions.
function formatInput(amount: string, unit?: string | ethers.Numeric): bigintParameters:
amount: The amount as a stringunit: (Optional) The unit of the amount (e.g., "18" for 18 decimal places)
Returns: The formatted bigint amount.
Example:
// Format 10 USDT for transaction (USDT has 6 decimal places)
const amount = formatInput('10', 6);
console.log(amount); // 10000000n
// Format 1.5 ETH for transaction (ETH has 18 decimal places)
const ethAmount = formatInput('1.5', 18);
console.log(ethAmount); // 1500000000000000000nformatOutput()
formatOutput()
Converts a bigint amount from blockchain to a human-readable number.
Parameters:
amount: The amount as bigint or numberunit: (Optional) The unit of the amount (e.g., "18" for 18 decimal places)
Returns: The formatted amount as a string.
Example:
Practical Examples
Working with Balances
Working with Different Tokens
Error Handling
Last updated