// Run: npx tsx examples/16-cosmos.ts import { Spectrum } from '@spectrumnodes/sdk'; const spectrum = new Spectrum({ api: process.env.SPECTRUM_API! }); // Example Cosmos Hub delegator address const DELEGATOR = 'cosmos1qpzry9x8gf2tvdw0s3jn54khce6mua7lmnxcl3'; async function main() { // --- getAccount --- const account = await spectrum.cosmos.getAccount('cosmoshub', DELEGATOR); console.log( `Account number: ${account.account.account_number}, sequence: ${account.account.sequence}`, ); // --- getStakingPool --- const pool = await spectrum.cosmos.getStakingPool('cosmoshub'); console.log(`\nBonded: ${pool.pool.bonded_tokens}, not bonded: ${pool.pool.not_bonded_tokens}`); // --- getValidators --- const validators = await spectrum.cosmos.getValidators('cosmoshub'); console.log(`\nValidators: ${validators.validators.length}`); const first = validators.validators[0]; if (first) { console.log(` ${first.description.moniker} — ${first.operator_address}`); // --- getValidator (single) --- const validator = await spectrum.cosmos.getValidator('cosmoshub', first.operator_address); console.log(` Commission rate: ${validator.validator.commission.commission_rates.rate}`); } // --- getDelegations --- const delegations = await spectrum.cosmos.getDelegations('cosmoshub', DELEGATOR); console.log(`\nDelegations: ${delegations.delegation_responses.length}`); // --- getUnbondingDelegations --- const unbonding = await spectrum.cosmos.getUnbondingDelegations('cosmoshub', DELEGATOR); console.log(`Unbonding: ${unbonding.unbonding_responses.length}`); // --- getStakingRewards (cosmoshub, osmosis, axelar, agoric) --- const rewards = await spectrum.cosmos.getStakingRewards('cosmoshub', DELEGATOR); console.log( `\nReward entries: ${rewards.rewards.length}, total: ${JSON.stringify(rewards.total)}`, ); // --- getDenomSupply --- const supply = await spectrum.cosmos.getDenomSupply('cosmoshub', 'uatom'); console.log(`\nuatom total supply: ${supply.amount.amount}`); // --- Cosmos token balance reuses the cross-chain tokens namespace. // `balance` is a decimal string (e.g. "12.5"); `balanceRaw` is the integer base-unit amount. --- const bal = await spectrum.tokens.getTokenBalance('cosmoshub', DELEGATOR, 'uatom'); console.log(`\nuatom balance: ${bal.balance} (raw: ${bal.balanceRaw})`); } main().catch(console.error);