getCostDetails

getCostDetails is a method on the ARIO class that calculates detailed cost information for a specific interaction (such as buying an ArNS record). The method determines costs based on the interaction type, the payer's address, and the funding source (balance, stake, or any available funds).

getCostDetails does not require authentication.

Parameters

← Swipe to see more →
ParameterTypeDescriptionOptional
intentstring

The type of interaction to calculate costs for (e.g., 'Buy-Record')

false
fromAddressstring - WalletAddress

The Arweave address that will be charged for the interaction

false
fundFromstring

The source of funds: 'balance', 'stakes', or 'any'

false
namestring

The ArNS name for the interaction (for Buy-Record operations)

conditional
typestring

The type of purchase: 'lease' or 'permabuy' (for Buy-Record operations)

conditional
yearsnumberNumber of years (for lease-based operations)conditional
quantitynumber

Quantity for operations like increasing undername limits

conditional
← Swipe to see more →

Examples

getCostDetails

const { ARIO } = require('@ar.io/sdk');

async function main() {
  const ario = ARIO.init();
  const costDetails = await ario.getCostDetails({
        intent: 'Buy-Record',
        fromAddress: 't4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3',
        fundFrom: 'stakes',
        name: 'ar-io',
        type: 'permabuy',
    });

    console.log(costDetails)
}

main();

Output

{
  "tokenCost": 2384252273,      // Total cost in IO tokens
  "fundingPlan": {
    "address": "t4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3", // Payer's address
    "balance": 0,               // Available balance
    "stakes": {                 // Available staked tokens
      "Rc80LG6h27Y3p9TN6J5hwDeG5M51cu671YwZpU9uAVE": {
        "vaults": [],           // Vault information
        "delegatedStake": 2384252273 // Amount of delegated stake
      }
    },
    "shortfall": 0             // Additional tokens needed (if any)
  },
  "discounts": []              // Any applicable discounts
}