MayaChain network integration using ShapeShift Unchained API.
npm install @pioneer-platform/maya-networkMayaChain network integration using ShapeShift Unchained API.
This module has been migrated from direct MayaChain node calls to use the Unchained API for better reliability and reduced node connection errors.
Primary: ShapeShift Unchained API
- Base URL: https://api.mayachain.shapeshift.com
- Documentation: https://api.mayachain.shapeshift.com/swagger
- Provides: Account info, balances, transaction history, broadcasting
Fallback: Midgard API
- Base URL: https://midgard.mayachain.info/v2
- Provides: Pool data, aggregated chain statistics
- Used for: Pool queries not available in Unchained
getInfo() - Network informationgetAccount(address) - Account details with balancesgetBalance(address) - Single CACAO balancegetBalances(address) - All asset balancestxs(address, cursor, pageSize) - Paginated transaction historybroadcast(rawTx) - Transaction broadcastinggetPools() - All liquidity poolsgetPool(poolId) - Specific pool detailsgetTransaction(txid) - Direct tx lookup (use account txs instead)getPoolAddress() - Inbound addresses (requires node access)``javascript
const network = require('@pioneer-platform/mayachain-network')
// Get network info
const info = await network.info()
// Get account balances
const balances = await network.getBalances('maya1...')
// Get transaction history (paginated)
const txs = await network.txs('maya1...', undefined, 50)
// Broadcast transaction
const result = await network.broadcast(signedTxBase64)
`
The module returns balances in standardized format:
`javascript`
[
{
denom: 'cacao', // Asset denomination
amountBase: '25029714637', // Raw amount (base units)
amount: 25.029714637, // Decimal amount
decimals: 10 // Decimal places
},
{
denom: 'maya',
amountBase: '4104',
amount: 0.4104,
decimals: 4
}
]
The module uses minimal logging with retry logic:
- 2 retries on 503 errors with exponential backoff
- Logs only errors and key operations (no verbose stack traces)
- Returns structured error responses for broadcast failures
2. ✅ Removed verbose error logging (no more giant stack traces)
3. ✅ Uses Unchained API for account/balance/tx operations
4. ✅ Keeps Midgard for pool data (not in Unchained)
5. ✅ Simplified retry logic with minimal logging$3
- Reliability: Unchained API is more stable than direct node access
- Performance: Faster responses, better caching
- Cleaner logs: No more 503 spam in logs
- Maintainability: Single API contract vs multiple node endpointsTesting
`bash
cd modules/coins/mayachain/mayachain-network
bun run test
`Test coverage:
- ✅ Network info retrieval
- ✅ Account balance queries
- ✅ Multi-asset balance parsing
- ✅ Transaction history (paginated)
- ✅ Pool data from Midgard
- 💬 Broadcasting (commented out - needs real signed tx)
Development
`bash
Build
bun run buildTest
bun run testInstall dependencies
bun install
`Dependencies
-
axios - HTTP client
- axios-retry - Retry logic for 503 errors
- @pioneer-platform/loggerdog` - LoggingMIT