Understanding formatters
WAX formatters allow you to:- Format numbers with locale-specific separators and precision
- Transform asset amounts from satoshis to decimal values
- Customize output based on data properties
- Create reusable formatting rules
- Match specific values with custom formatters
Formatters are primarily available in TypeScript. Python uses simpler formatting utilities.
Creating a formatter
Thewaxify function creates formatters for template literals.
- TypeScript
Using waxify
Thewaxify function creates tagged template literals for formatting.
- TypeScript
Formatting numbers
Format numbers with locale-specific separators and precision.- TypeScript
WAX formatters can handle numbers larger than JavaScript’s
MAX_SAFE_INTEGER by working with string representations.Formatting assets
Format cryptocurrency amounts from satoshis to human-readable values.- TypeScript
- Python
Custom formatters
Create custom formatters for specific data types or patterns.- TypeScript
Property matchers
Match specific property names for custom formatting.- TypeScript
Instance matchers
Match specific object types or classes.- TypeScript
Formatter options
Customize formatter behavior with options.- TypeScript
Complete example
Here’s a complete example using formatters to display account information.- TypeScript
Best practices
Create reusable formatter classes
Create reusable formatter classes
Group related formatting logic into reusable classes.
Handle edge cases in custom formatters
Handle edge cases in custom formatters
Always handle undefined, null, or invalid values.
Test formatters with various locales
Test formatters with various locales
If your app supports multiple locales, test formatting with each.
Next steps
Building transactions
Start building transactions with WAX
Complex operations
Use high-level operation helpers
TypeScript API
Explore the full API reference
Examples
See more formatting examples