PixelBridge Core
  • What is PixelBridge Core?
  • ⚪PRODUCT
    • How does PixelBridge Core work?
      • Fees
      • Messaging protocols
      • PixelBridge Core contracts
      • Token value
      • Liquidity provision
    • PixelBridge Core guide
    • How to provide liquidity?
    • How to bridge with PixelBridge Core via mobile TronLink
    • Security audit
  • ⚪PixelBridge CORE SDK
    • Get started
    • Guides
      • General
        • Token info
        • Send
        • Swap
        • Paying fees with stables
      • EVM
        • Transfer
        • Allowance and approve
      • Solana
        • Transfer
        • Swap
      • Stellar
        • Transfer
      • Utilities
        • Amount and fee calculations
        • Transfer time
        • Extra gas limits
  • ⚪SOCIAL LINKS
    • Twtter
    • Telegram
    • Medium
  • ⚪PixelBridge ECOSYSTEM
    • PixelBridge Classic
    • PixelBridge BaaS
Powered by GitBook
On this page
  1. ⚪PixelBridge CORE SDK
  2. Guides
  3. Utilities

Amount and fee calculations

To calculate and get info about the receive amount, one has to call getAmountToBeReceived 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.PixelBridge);

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
);

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

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
);

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

const { amountToSendFloat, amountToBeReceivedFloat, gasFeeOptions } = await sdk.getAmountToBeReceivedAndGasFeeOptions(
  amount,
  sourceToken,
  destinationToken,
  Messenger.PixelBridge
);
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
);
PreviousUtilitiesNextTransfer time

Last updated 12 months ago