Allbridge Core
LAUNCH APP
  • What is Allbridge Core?
  • ⚪Product
    • How does Allbridge Core work?
      • Fees
      • Messaging protocols
      • Allbridge Core contracts
      • Token value
      • Liquidity provision
    • FAQ
      • How to bridge with Allbridge Core via mobile TronLink
      • Allbridge Core guide
      • How to provide liquidity?
      • What is an Approve Transaction?
    • Security audits
    • Ecosystem reports
    • Leaderboard
  • ⚪Allbridge Core SDK
    • Get started
    • Guides
      • General
        • Token info
        • Send
        • Swap
        • Paying fees with stables
      • EVM
        • Transfer
        • Allowance and approve
      • Solana
        • Transfer
        • Swap
      • Tron
      • Stellar
        • Transfer
      • Utilities
        • Amount and fee calculations
        • Transfer time
        • Extra gas limits
    • Technical reference
    • Referral program
    • Allbridge Core REST API
  • ⚪official support
    • Telegram
    • Discord
  • ⚪Social links
    • Twitter
    • Discord
    • Telegram announcements
    • Telegram group
    • Medium
    • Reddit
  • ⚪Allbridge ecosystem
    • Allbridge Classic
    • Allbridge BaaS
Powered by GitBook
On this page

Was this helpful?

  1. Allbridge Core SDK
  2. Guides
  3. Utilities

Amount and fee calculations

PreviousUtilitiesNextTransfer time

Last updated 8 months ago

Was this helpful?

To calculate and get info about the receive amount, one has to call method.

const amountToBeReceived = await sdk.getAmountToBeReceived(amount, sourceToken, destinationToken);
console.log(
  "Send %d %s and %d %s (gas fee) on %s to receive %d %s on %s",
  amount,
  sourceToken.symbol,
  gasFeeOptions.native.int,
  sourceChainMinUnit,
  sourceToken.chainSymbol,
  amountToBeReceived,
  destinationToken.symbol,
  destinationToken.chainSymbol
);

If you selected pay with stables:

const gasFeeOptions = await sdk.getGasFeeOptions(sourceToken, destinationToken, Messenger.ALLBRIDGE);

const floatGasFeeAmount = gasFeeOptions.stablecoin.float;
console.log(
  "Send %d %s and %d %s (gas fee) on %s to receive %d %s on %s",
  amount,
  sourceToken.symbol,
  floatGasFeeAmount,
  sourceToken.symbol,
  sourceToken.chainSymbol,
  amountToBeReceived,
  destinationToken.symbol,
  destinationToken.chainSymbol
);
const amountToSend = await sdk.getAmountToSend(amount, sourceToken, destinationToken);
console.log(
  "Send %d %s and %d %s (gas fee) on %s to receive %d %s on %s",
  amountToSend,
  sourceToken.symbol,
  gasFeeOptions.native.int,
  sourceChainMinUnit,
  sourceToken.chainSymbol,
  amount,
  destinationToken.symbol,
  destinationToken.chainSymbol
);
const { amountToSendFloat, amountToBeReceivedFloat, gasFeeOptions } = await sdk.getAmountToBeReceivedAndGasFeeOptions(
  amount,
  sourceToken,
  destinationToken,
  Messenger.ALLBRIDGE
);
console.log(
  "Send %d %s and %d %s (gas fee) on %s to receive %d %s on %s",
  amountToSendFloat,
  sourceToken.symbol,
  gasFeeOptions.native.int,
  sourceChainMinUnit,
  sourceToken.chainSymbol,
  amountToBeReceivedFloat,
  destinationToken.symbol,
  destinationToken.chainSymbol
);

If you want to calculate how much you need to send to receive a specific amount use a method:

If you want to receive additional data about fees, select or method instead:

⚪
getAmountToBeReceived
getAmountToSend
getAmountToBeReceivedAndGasFeeOptions
getAmountToSendAndGasFeeOptions
Full example