Moonbeam XCM SDK Reference: Methods
The SDK provides an API that enables you to get asset information for each supported asset, the source chains where a given asset can be sent from, and, given a source chain, the supported destination chains where the given asset can be sent. The SDK also includes helper methods related to transferring cross-chain assets, such as getting an estimated amount of the asset the destination account will receive, less any execution fees, and asset conversion methods based on the asset and the number of decimals it has. All of these enable you to transfer assets across chains easily and seamlessly.
The following sections cover the available methods in the XCM SDK.
Initialize the SDK
Sdk()
- Exposes the methods of the XCM SDK. Must be called first to access other SDK methods.
Parameters
options?
SdkOptions - Allows you to specify anevmSigner
orpolkadotSigner
Returns
The Get Transfer Data Method
getTransferData()
- Builds the data necessary to transfer an asset between a source chain and a destination chain.
Parameters
destinationAddress
string - The address of the receiving account on the destination chaindestinationKeyorChain
string | AnyChain - The key orChain
data for the destination chainevmSigner?
EvmSigner - The signer for Ethereum-compatible chains that use H160 Ethereum-style accounts. Can be an Ethers signer or a viem Wallet ClientkeyOrAsset
string | Asset - The key orAsset
data for the asset being transferredpolkadotSigner?
PolkadotSigner | IKeyringPair - The Polkadot signer or Keyring pairsourceAddress
string - The address of the sending account on the source chainsourceKeyOrChain
string | AnyChain - The key orChain
data for the source chain
Returns
-
Promise<TransferData> - The assembled transfer data, which includes the following:
-
destination
DestinationChainTransferData - The assembled destination chain and address information getEstimate
function - Gets the estimated amount of the asset that the destination address will receiveisSwapPossible
boolean - Returns whether or not the swap is possiblemax
AssetAmount - The maximum amount of the asset that can be transferredmin
AssetAmount - The minimum amount of the asset that can be transferredsource
SourceChainTransferData - The assembled source chain and address informationswap
function - Swaps the destination and the source chains and returns the swapped transfer datatransfer
function - Transfers a given amount of the asset from the source chain to the destination chain
const transferData = await Sdk().getTransferData({
destinationAddress: 'INSERT_MOONBEAM_ADDRESS',
destinationKeyOrChain: 'moonbeam',
evmSigner: INSERT_EVM_SIGNER,
keyOrAsset: 'dot',
polkadotSigner: INSERT_POLKADOT_SIGNER,
sourceAddress: 'INSERT_POLKADOT_ADDRESS',
sourceKeyOrChain: {
key: 'polkadot',
name: 'polkadot',
type: 'parachain',
},
});
console.log(transferData);
{
destination: {
balance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
chain: {
ecosystem: 'polkadot',
isTestChain: false,
key: 'moonbeam',
name: 'Moonbeam',
type: 'evm-parachain',
assetsData: [Map],
genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d',
parachainId: 2004,
ss58Format: 1284,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://wss.api.moonbeam.network',
id: 1284,
rpc: 'https://rpc.api.moonbeam.network'
},
existentialDeposit: {
key: 'glmr',
originSymbol: 'GLMR',
amount: 0n,
decimals: 18,
symbol: 'GLMR'
},
fee: {
key: 'dot',
originSymbol: 'DOT',
amount: 20080321n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
}
},
getEstimate: [Function: getEstimate],
isSwapPossible: true,
max: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 20080321n,
decimals: 10,
symbol: 'DOT'
},
source: {
balance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
chain: {
ecosystem: 'polkadot',
isTestChain: false,
key: 'polkadot',
name: 'Polkadot',
type: 'parachain',
assetsData: Map(0) {},
genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
parachainId: 0,
ss58Format: 0,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://polkadot-rpc.dwellir.com'
},
destinationFeeBalance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
existentialDeposit: {
key: 'dot',
originSymbol: 'DOT',
amount: 10000000000n,
decimals: 10,
symbol: 'DOT'
},
fee: {
key: 'dot',
originSymbol: 'DOT',
amount: 163633495n,
decimals: 10,
symbol: 'DOT'
},
feeBalance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
max: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
}
},
swap: [AsyncFunction: swap],
transfer: [AsyncFunction: transfer]
}
The Assets Method
assets()
- Provides an entry point for building the data necessary to transfer an asset between a source chain and a destination chain.
Parameters
ecosystem?
Ecosystem - Specify the ecosystem for a set of assets:polkadot
,kusama
, oralphanet-relay
Returns
Build the Transfer Data Starting with Assets
When building transfer data with the Sdk().assets()
function, you'll use multiple methods to build and send the underlying XCM message.
The Asset Method
asset()
- Sets the asset to be transferred. Must call assets()
first.
Parameters
Returns
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const sourceData = sdkInstance.assets().asset('dot');
console.log(sourceData);
{
sourceChains: [
{
ecosystem: 'polkadot',
isTestChain: false,
key: 'moonbeam',
name: 'Moonbeam',
type: 'evm-parachain',
assetsData: {
'aca' => {
asset: { key: 'aca', originSymbol: 'ACA' },
id: '224821240862170613278369189818311486111'
},
'astr' => {
asset: { key: 'astr', originSymbol: 'ASTR' },
id: '224077081838586484055667086558292981199'
},
...
},
genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d',
parachainId: 2004,
ss58Format: 1284,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://wss.api.moonbeam.network',
id: 1284,
rpc: 'https://rpc.api.moonbeam.network',
nativeCurrency: {
decimals: 18,
name: 'GLMR',
symbol: 'GLMR'
}
},
{
ecosystem: 'polkadot',
isTestChain: false,
key: 'polkadot',
name: 'Polkadot',
type: 'parachain',
assetsData: Map(0) {},
genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
parachainId: 0,
ss58Format: 0,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://polkadot-rpc.dwellir.com'
}
],
source: [Function: source]
}
The Source Method
source()
- Sets the source chain from which to transfer the asset. Must call asset()
first.
Parameters
Returns
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const destinationData = sdkInstance.assets().asset('dot').source('polkadot');
console.log(destinationData);
{
destinationChains: [
{
ecosystem: 'polkadot',
isTestChain: false,
key: 'moonbeam',
name: 'Moonbeam',
type: 'evm-parachain',
assetsData: {
'aca' => {
asset: { key: 'aca', originSymbol: 'ACA' },
id: '224821240862170613278369189818311486111'
},
'astr' => {
asset: { key: 'astr', originSymbol: 'ASTR' },
id: '224077081838586484055667086558292981199'
},
...
},
genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d',
parachainId: 2004,
ss58Format: 1284,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://wss.api.moonbeam.network',
id: 1284,
rpc: 'https://rpc.api.moonbeam.network',
nativeCurrency: {
decimals: 18,
name: 'GLMR',
symbol: 'GLMR'
}
}
],
destination: [Function: destination]
}
The Destination Method
destination()
- Sets the destination chain to which to transfer the asset. Must call source()
first.
Parameters
Returns
The Accounts Method
accounts()
- Sets the source address, the destination address, and the signer(s) required for the transfer. Must call destination()
first.
Parameters
sourceAddress
string - The address of the sending account on the source chaindestinationAddress
string - The address of the receiving account on the destination chainsigners?
Partial(signers) - The EVM or Polkadot signers required to sign transactions
Returns
-
Promise<TransferData> - The assembled transfer data, which includes the following:
-
destination
DestinationChainTransferData - The assembled destination chain and address information getEstimate
function - Gets the estimated amount of the asset that the destination address will receiveisSwapPossible
boolean - Returns whether or not the swap is possiblemax
AssetAmount - The maximum amount of the asset that can be transferredmin
AssetAmount - The minimum amount of the asset that can be transferredsource
SourceChainTransferData - The assembled source chain and address informationswap
function - Swaps the destination and the source chains and returns the swapped transfer datatransfer
function - Transfers a given amount of the asset from the source chain to the destination chain
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
console.log(transferData);
{
destination: {
balance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
chain: {
ecosystem: 'polkadot',
isTestChain: false,
key: 'moonbeam',
name: 'Moonbeam',
type: 'evm-parachain',
assetsData: [Map],
genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d',
parachainId: 2004,
ss58Format: 1284,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://wss.api.moonbeam.network',
id: 1284,
rpc: 'https://rpc.api.moonbeam.network'
},
existentialDeposit: {
key: 'glmr',
originSymbol: 'GLMR',
amount: 0n,
decimals: 18,
symbol: 'GLMR'
},
fee: {
key: 'dot',
originSymbol: 'DOT',
amount: 20080321n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
}
},
getEstimate: [Function: getEstimate],
isSwapPossible: true,
max: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 20080321n,
decimals: 10,
symbol: 'DOT'
},
source: {
balance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
chain: {
ecosystem: 'polkadot',
isTestChain: false,
key: 'polkadot',
name: 'Polkadot',
type: 'parachain',
assetsData: Map(0) {},
genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
parachainId: 0,
ss58Format: 0,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://polkadot-rpc.dwellir.com'
},
destinationFeeBalance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
existentialDeposit: {
key: 'dot',
originSymbol: 'DOT',
amount: 10000000000n,
decimals: 10,
symbol: 'DOT'
},
fee: {
key: 'dot',
originSymbol: 'DOT',
amount: 163633495n,
decimals: 10,
symbol: 'DOT'
},
feeBalance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
max: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
}
},
swap: [AsyncFunction: swap],
transfer: [AsyncFunction: transfer]
}
Consume Transfer Data
The Swap Method
swap()
- Returns the transfer data necessary to swap the asset from the destination chain back to the source chain.
Parameters
None.
Returns
-
Promise<TransferData | undefined> - If the swap is not possible,
undefined
is returned. If the swap is possible, the assembled transfer data is returned, which includes the following: -
destination
DestinationChainTransferData - The assembled destination chain and address information getEstimate
function - Gets the estimated amount of the asset that the destination address will receiveisSwapPossible
boolean - Returns whether or not the swap is possiblemax
AssetAmount - The maximum amount of the asset that can be transferredmin
AssetAmount - The minimum amount of the asset that can be transferredsource
SourceChainTransferData - The assembled source chain and address informationswap
function - Swaps the destination and the source chains and returns the swapped transfer datatransfer
function - Transfers a given amount of the asset from the source chain to the destination chain
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const swapData = await transferData.swap();
console.log(swapData);
{
destination: {
balance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
chain: {
ecosystem: 'polkadot',
isTestChain: false,
key: 'polkadot',
name: 'Polkadot',
type: 'parachain',
assetsData: Map(0) {},
genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
parachainId: 0,
ss58Format: 0,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://polkadot-rpc.dwellir.com'
},
existentialDeposit: {
key: 'dot',
originSymbol: 'DOT',
amount: 10000000000n,
decimals: 10,
symbol: 'DOT'
},
fee: {
key: 'dot',
originSymbol: 'DOT',
amount: 520000000n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
}
},
getEstimate: [Function: getEstimate],
isSwapPossible: true,
max: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 10520000000n,
decimals: 10,
symbol: 'DOT'
},
source: {
balance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
chain: {
ecosystem: 'polkadot',
isTestChain: false,
key: 'moonbeam',
name: 'Moonbeam',
type: 'evm-parachain',
assetsData: {
'aca' => {
asset: { key: 'aca', originSymbol: 'ACA' },
id: '224821240862170613278369189818311486111'
},
'astr' => {
asset: { key: 'astr', originSymbol: 'ASTR' },
id: '224077081838586484055667086558292981199'
},
...
},
genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d',
parachainId: 2004,
ss58Format: 1284,
usesChainDecimals: false,
weight: undefined,
ws: 'wss://wss.api.moonbeam.network',
id: 1284,
rpc: 'https://rpc.api.moonbeam.network',
nativeCurrency: {
decimals: 18,
name: 'GLMR',
symbol: 'GLMR'
}
},
destinationFeeBalance: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
existentialDeposit: {
key: 'glmr',
originSymbol: 'GLMR',
amount: 0n,
decimals: 18,
symbol: 'GLMR'
},
fee: {
key: 'glmr',
originSymbol: 'GLMR',
amount: 0n,
decimals: 18,
symbol: 'GLMR'
},
feeBalance: {
key: 'glmr',
originSymbol: 'GLMR',
amount: 0n,
decimals: 18,
symbol: 'GLMR'
},
max: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
},
min: {
key: 'dot',
originSymbol: 'DOT',
amount: 0n,
decimals: 10,
symbol: 'DOT'
}
},
swap: [AsyncFunction: swap],
transfer: [AsyncFunction: transfer]
}
The Transfer Method
transfer()
- Transfers a given amount of the asset from the source chain to the destination chain.
Parameters
amount
bigint | number| string - The amount of the asset to transfer between the source and destination chains
Returns
- Promise(string) - The transaction hash for the transfer on the source chain
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const transferTxHash = await transferData.transfer();
console.log(transferTxHash);
The Get Estimate Method
getEstimate()
- Returns an estimated amount of the asset that will be received on the destination chain, less any destination fees.
Parameters
amount
number | string - The amount of the asset to transfer between the source and destination chains
Returns
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const estimate = transferData.getEstimate(1);
console.log(estimate);
Asset Utilities
The AssetAmount
class contains the following utility functions.
The From Asset Method
fromAsset()
- Creates an AssetAmount
instance from an Asset
and some additional parameters.
Note
To use the fromAsset
method, you'll need to import it from the xcm-types package. To install the xcm-types package, run the following:
Parameters
asset
AssetAmount - AnAssetAmount
instance to compareparams
AssetAmountParams - Additional parameters needed to create theAssetAmount
instance. TheAssetAmountParams
are as follows:amount
bigint - Identifies a particular amount of the asset (i.e., balance, minimum, maximum, etc.)decimals
number - The number of decimals the asset hassymbol
string - The symbol of the asset
Returns
Returns
The Is Same Method
isSame()
- Compares two instances of AssetAmount
and checks whether they have the same name
, symbol
, and decimals
properties. This method does not compare the amount
properties.
Parameters
Returns
- boolean -
true
if theAssetAmount
instances are the same orfalse
if they are different
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const isSame = transferData.max.isSame(transferData.min);
console.log(isSame);
The Is Equal Method
isEqual()
- Compares two instances of AssetAmount
and checks whether they have all of the same properties. This compares the name
, symbol
, decimals
, and amount
properties.
Parameters
Returns
- boolean -
true
if theAssetAmount
instances are the same orfalse
if they are different
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const isEqual = transferData.max.isEqual(transferData.min);
console.log(isEqual);
The Copy With Method
copyWith()
- Creates a new instance of AssetAmount
with properties of the original instance and overrides properties that are passed as options.
Parameters
params
Partial<AssetAmountConstructorParams> - The properties to apply to the newAssetAmount
instance. TheAssetAmountConstructorParams
are as follows:amount
bigint - Identifies a particular amount of the asset (i.e., balance, minimum, maximum, etc.)decimals
number - The number of decimals the asset hassymbol
string - The symbol of the asset
Returns
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const estimate = transferData.getEstimate(1);
const estimateCopy = estimate.copyWith({ amount: 2 });
console.log(estimateCopy);
The To Decimal Method
toDecimal()
- Converts an AssetAmount
to a decimal. The number to convert to decimal format and the number of decimals the asset uses are pulled automatically from the AssetAmount
.
Parameters
maxDecimal?
number - The maximum number of decimal places to use. the default is6
roundType?
RoundingMode - Accepts an index that dictates the rounding method to use based on theRoundingMode
enum:
Returns
- string - The given amount in decimal format
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const estimate = transferData.getEstimate(1);
const estimateAmount = estimate.toDecimal();
console.log(estimateAmount);
The To Big Number Method
toBig()
- Converts an AssetAmount
to a big number.
Parameters
None.
Returns
- Big - The given amount in big number format
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const fee = transferData.destination.fee.toBig();
console.log(fee);
The To Big Decimal Method
toBigDecimal()
- Converts an AssetAmount
to a decimal and then to a big number. The number to convert to decimal format and the number of decimals the asset uses are pulled automatically from the AssetAmount
.
Parameters
maxDecimal?
number - The maximum number of decimal places to use. the default is6
roundType?
RoundingMode - Accepts an index that dictates the rounding method to use based on theRoundingMode
enum:
Returns
- Big - The given amount in big number decimal format
import { Sdk } from '@moonbeam-network/xcm-sdk';
const sdkInstance = Sdk();
const transferData = await sdkInstance
.assets()
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(
INSERT_POLKADOT_ADDRESS, // Source chain address
INSERT_MOONBEAM_ADDRESS, // Destination chain address
{
evmSigner: INSERT_EVM_SIGNER,
polkadotSigner: INSERT_POLKADOT_SIGNER,
},
);
const fee = transferData.destination.fee.toBigDecimal();
console.log(fee);