diff --git a/mkdocs/docs/example-usage.md b/mkdocs/docs/example-usage.md index 361531fe..8c35b1a6 100644 --- a/mkdocs/docs/example-usage.md +++ b/mkdocs/docs/example-usage.md @@ -30,25 +30,18 @@ You'll also need to install a few additional dependencies that you'll use to int npm install @polkadot/api @polkadot/util-crypto ``` -You'll also need an Ethereum signer if you're interacting with an Ethereum-compatible chain like Moonbeam. This guide will cover using Ethers.js and viem. You'll need to install whichever library you want to use: +You'll also need an Ethereum signer if you're interacting with an Ethereum-compatible chain like Moonbeam. For that you'll need to install [viem](https://viem.sh/docs/installation){target=\_blank}: -=== "Ethers.js" - ```bash - npm install ethers@6 - ``` - -=== "viem" - - ```bash - npm install viem@2 - ``` +```bash +npm install viem@2 +``` ## Create Signers {: #create-signers } -When transferring assets between chains, you'll need signers in place to sign the transactions. If you're interacting with an Ethereum-compatible chain that uses standard Ethereum-style H160 addresses, such as Moonbeam, you'll need to have an Ethereum signer, which can be an [Ethers.js](https://docs.ethers.org/v5/){target=\_blank} signer or a [viem Wallet Client](https://viem.sh/docs/clients/wallet.html){target=\_blank}. To interact with the relay chain or other parachains, you'll need a [Polkadot](https://polkadot.js.org/docs/api/){target=\_blank} signer. +When transferring assets between chains, you'll need signers in place to sign the transactions. If you're interacting with an Ethereum-compatible chain that uses standard Ethereum-style H160 addresses, such as Moonbeam, you'll need to have an Ethereum signer, like a [viem Wallet Client](https://viem.sh/docs/clients/wallet.html){target=\_blank}. To interact with the relay chain or other parachains, you'll need a [Polkadot](https://polkadot.js.org/docs/api/){target=\_blank} signer. -You can pass, for example, a [browser extension wallet as a signer into Ethers](https://docs.ethers.org/v5/getting-started/#getting-started--connecting){target=\_blank} or [viem](https://viem.sh/docs/clients/wallet.html#json-rpc-accounts){target=\_blank}, such as MetaMask. Similarly, with Polkadot, you can [pass a compatible wallet to the signer using the `@polkadot/extension-dapp` library](https://polkadot.js.org/docs/extension/){target=\_blank}. +You can pass, for example, a [browser extension wallet as a signer into viem](https://viem.sh/docs/clients/wallet.html#json-rpc-accounts){target=\_blank}, such as MetaMask. Similarly, with Polkadot, you can [pass a compatible wallet to the signer using the `@polkadot/extension-dapp` library](https://polkadot.js.org/docs/extension/){target=\_blank}. To create an EVM signer and a Polkadot signer, you can refer to the following sections. @@ -57,84 +50,21 @@ To create an EVM signer and a Polkadot signer, you can refer to the following se ### Create an EVM Signer {: #create-a-evm-signer } -To create an Ethers signer, you can use the following code snippet: - -```js -import { ethers } from 'ethers'; - -const privateKey = 'INSERT_PRIVATE_KEY'; -const provider = new ethers.WebSocketProvider('INSERT_WS_ENDPOINT', { - chainId: INSERT_CHAIN_ID, - name: 'INSERT_CHAIN_NAME', -}); -const evmSigner = new ethers.Wallet(privateKey, provider); -``` - -For Moonbeam specifically, you can use the following configurations: - -=== "Moonbeam" - - ```js - import { ethers } from 'ethers'; - - const privateKey = 'INSERT_PRIVATE_KEY'; - const provider = new ethers.WebSocketProvider( - '{{ networks.moonbeam.wss_url }}', - { - chainId: {{ networks.moonbeam.chain_id }}, - name: 'moonbeam', - } - ); - const evmSigner = new ethers.Wallet(privateKey, provider); - ``` - -=== "Moonriver" - - ```js - import { ethers } from 'ethers'; - - const privateKey = 'INSERT_PRIVATE_KEY'; - const provider = new ethers.WebSocketProvider( - '{{ networks.moonriver.wss_url }}', - { - chainId: {{ networks.moonriver.chain_id }}, - name: 'moonriver', - } - ); - const evmSigner = new ethers.Wallet(privateKey, provider); - ``` - -=== "Moonbase Alpha" - - ```js - import { ethers } from 'ethers'; - - const privateKey = 'INSERT_PRIVATE_KEY'; - const provider = new ethers.WebSocketProvider( - '{{ networks.moonbase.wss_url }}', - { - chainId: {{ networks.moonbase.chain_id }}, - name: 'moonbase', - } - ); - const evmSigner = new ethers.Wallet(privateKey, provider); - ``` - -Alternatively, you can create a viem Wallet Client to pass as an EVM signer: +You can create a viem Wallet Client to pass as an EVM signer. Here are some examples of configurations: === "Moonbeam" ```js - import { createWalletClient, http } from 'viem'; + import { moonbeam } from '@moonbeam-network/xcm-config'; + import { createWalletClient, http, type Address } from 'viem'; import { privateKeyToAccount } from 'viem/accounts' - import { moonbeam } from 'viem/chains'; const privateKey = 'INSERT_PRIVATE_KEY'; - const account = privateKeyToAccount(privateKey); + const account = privateKeyToAccount(privateKey as Address); const evmSigner = createWalletClient({ account, - chain: moonbeam, + chain: moonbeam.getViemChain(), transport: http(), }); ``` @@ -142,16 +72,16 @@ Alternatively, you can create a viem Wallet Client to pass as an EVM signer: === "Moonriver" ```js - import { createWalletClient, http } from 'viem'; + import { moonriver } from '@moonbeam-network/xcm-config'; + import { createWalletClient, http, type Address } from 'viem'; import { privateKeyToAccount } from 'viem/accounts' - import { moonriver } from 'viem/chains'; const privateKey = 'INSERT_PRIVATE_KEY'; - const account = privateKeyToAccount(privateKey); + const account = privateKeyToAccount(privateKey as Address); const evmSigner = createWalletClient({ account, - chain: moonriver, + chain: moonriver.getViemChain(), transport: http(), }); ``` @@ -159,16 +89,16 @@ Alternatively, you can create a viem Wallet Client to pass as an EVM signer: === "Moonbase Alpha" ```js - import { createWalletClient, http } from 'viem'; + import { moonbaseAlpha } from '@moonbeam-network/xcm-config'; + import { createWalletClient, http, type Address } from 'viem'; import { privateKeyToAccount } from 'viem/accounts' - import { moonbaseAlpha } from 'viem/chains'; const privateKey = 'INSERT_PRIVATE_KEY'; - const account = privateKeyToAccount(privateKey); + const account = privateKeyToAccount(privateKey as Address); const evmSigner = createWalletClient({ account, - chain: moonbaseAlpha, + chain: moonbaseAlpha.getViemChain(), transport: http(), }); ``` @@ -178,11 +108,11 @@ If you want to pass in a browser extension wallet to viem, you can use the follo === "Moonbeam" ```js + import { moonbeam } from '@moonbeam-network/xcm-config'; import { createWalletClient, custom } from 'viem'; - import { moonbeam } from 'viem/chains'; const evmSigner = createWalletClient({ - chain: moonbeam, + chain: moonbeam.getViemChain(), transport: custom(window.ethereum), }); ``` @@ -190,11 +120,11 @@ If you want to pass in a browser extension wallet to viem, you can use the follo === "Moonriver" ```js + import { moonriver } from '@moonbeam-network/xcm-config'; import { createWalletClient, custom } from 'viem'; - import { moonriver } from 'viem/chains'; const evmSigner = createWalletClient({ - chain: moonriver, + chain: moonriver.getViemChain(), transport: custom(window.ethereum), }); ``` @@ -202,11 +132,11 @@ If you want to pass in a browser extension wallet to viem, you can use the follo === "Moonbase Alpha" ```js + import { moonbaseAlpha } from '@moonbeam-network/xcm-config'; import { createWalletClient, custom } from 'viem'; - import { moonbaseAlpha } from 'viem/chains'; const evmSigner = createWalletClient({ - chain: moonbaseAlpha, + chain: moonbaseAlpha.getViemChain(), transport: custom(window.ethereum), }); ``` @@ -216,9 +146,10 @@ If you want to pass in a browser extension wallet to viem, you can use the follo ### Create a Polkadot Signer {: #create-a-polkadot-signer } -In this example, you can use a [Polkadot.js Keyring](https://polkadot.js.org/docs/api/start/keyring/){target=\_blank} to sign transactions. Please note that this approach is not recommended for production applications. +In this example, you can use a [Polkadot.js Keyring](https://polkadot.js.org/docs/api/start/keyring/){target=\_blank} to sign transactions. Please note that this approach is not recommended for production applications. ```js +import { polkadot } from '@moonbeam-network/xcm-config'; import { Keyring } from '@polkadot/api'; import { cryptoWaitReady } from '@polkadot/util-crypto'; @@ -227,7 +158,7 @@ const privateKey = 'INSERT_PRIVATE_KEY'; const createPolkadotSigner = async () => { await cryptoWaitReady(); const keyring = new Keyring({ - ss58Format: 'INSERT_SS58_FORMAT', + ss58Format: polkadot.ss58Format, type: 'sr25519', }); const pair = keyring.createFromUri(privateKey); @@ -251,50 +182,54 @@ To get a list of all of the assets supported by the XCM SDK, you can instantiate import { Sdk } from '@moonbeam-network/xcm-sdk'; const sdkInstance = Sdk(); -const assets = sdkInstance.assets(); +const assets = sdkInstance.assets; console.log('The supported assets are as follows:'); -assets.assets.forEach((asset) => { +assets.forEach((asset) => { console.log(`- ${asset.originSymbol}`); }); ``` ### Get List of Supported Assets by Ecosystem {: #get-supported-assets-by-ecosystem } + To get a list of the supported assets for a particular [ecosystem](./reference/interfaces.md#the-ecosystem-type), you can pass in the ecosystem name: `polkadot`, `kusama`, or `alphanet-relay`. For example, the following snippet will get all of the Polkadot assets supported: ```js import { Sdk } from '@moonbeam-network/xcm-sdk'; +import { Ecosystem } from '../../packages/types/build'; -const sdkInstance = Sdk(); -const assets = sdkInstance.assets('polkadot'); +const sdkInstance = Sdk({ ecosystem: Ecosystem.Polkadot }); +const assets = sdkInstance.assets; console.log( 'The supported assets within the Polkadot ecosystem are as follows:', ); -assets.assets.forEach((asset) => { +assets.forEach((asset) => { console.log(`- ${asset.originSymbol}`); }); -``` -### Get List of Supported Chains by Asset {: #get-list-of-supported-assets-by-chain } +``` -To get a list of the supported [source](./reference/methods.md#the-source-method) and [destination](./reference/methods.md#the-destination-method) chains for a given asset, you can use the following code snippet, which logs the supported chains by asset for all of the supported assets in the Polkadot ecosystem: +### Get List of Supported Routes by Asset {: #get-list-of-supported-routes-by-asset } + +To get a list of the supported [source](./reference/methods.md#the-source-method) and [destination](./reference/methods.md#the-destination-method) chains for a given asset, you can use the following code snippet, which logs the supported routes by asset for all of the supported assets in the Polkadot ecosystem: ```js import { Sdk } from '@moonbeam-network/xcm-sdk'; +import { Ecosystem } from '../../packages/types/build'; -const sdkInstance = Sdk(); -const assets = sdkInstance.assets('polkadot'); +const sdkInstance = Sdk({ ecosystem: Ecosystem.Polkadot }); +const assets = sdkInstance.assets; -assets.assets.forEach((asset) => { - const { sourceChains, source } = assets.asset(asset); +assets.forEach((asset) => { + const { sources, setSource } = sdkInstance.setAsset(asset); console.log(`You can send ${asset.originSymbol}...`); - if (sourceChains.length > 1) { - sourceChains.forEach((sourceChain) => { - const { destinationChains } = source(sourceChain); - if (destinationChains.length > 0) { - destinationChains.forEach((destination) => { + if (sources.length > 1) { + sources.forEach((source) => { + const { destinations } = setSource(source); + if (destinations.length > 0) { + destinations.forEach((destination) => { console.log(`- From ${source.name} to ${destination.name}`); }); } @@ -307,125 +242,137 @@ assets.assets.forEach((asset) => { To transfer an asset from one chain to another, you'll need to first build the transfer data, which defines the asset to be transferred, the source chain and address, the destination chain and address, and the associated signer for the transaction. Building the transfer data is the first step; in the next section, you'll learn how to use it to actually transfer the asset. -To get started, you'll use the [`Sdk`](./reference/methods.md#initialize-the-sdk) function, which will expose two methods for building the XCM transfer data: [`assets`](./reference/methods.md#the-assets-method) and [`getTransferData`](./reference/methods.md#the-get-transfer-data-method). +In this guide, we'll show you first how to build the transfer data if you already know the route you want to use and don't need chain or asset information. Then, we'll show you how to build the transfer data if you need to retrieve the list of supported assets and chains for a given asset, which is useful if you're building a UI to allow users to select the asset, source, and destination chains. + + +### Simple Example {: #build-xcm-transfer-data-simple } + +In this example, we want to transfer DOT from Polkadot to Moonbeam. So to get the transfer data, we'll need to set the asset, source, and destination chains. First we'll need to instantiate the SDK, by calling the [`Sdk`](./reference/methods.md#initialize-the-sdk) function and then calling the `setAsset`, `setSource`, and `setDestination` functions. +You can optionally pass in the ecosystem to the `Sdk` function, but in this example, we know the route we want to use, so there is no need to pass in the ecosystem. ```js import { Sdk } from '@moonbeam-network/xcm-sdk'; +import { dot, polkadot, moonbeam } from '@moonbeam-network/xcm-config'; -const sdkInstance = Sdk(); +const fromPolkadot = async () => { + const transferData = await Sdk() + .setAsset(dot) + .setSource(polkadot) + .setDestination(moonbeam) +.setAddresses({ + sourceAddress: pair.address, + destinationAddress: account.address, + }); +}; + +fromPolkadot(); ``` + +### Example with assets and chains information {: #build-xcm-transfer-data-information } -You can choose either method, as both will return the data necessary to initiate an asset transfer between the source and destination chains. Using `assets` will provide additional data along the way, including the list of supported assets and, once an asset is selected, the supported source and destination chains that can send and receive it. + +To get started, you'll use the [`Sdk`](./reference/methods.md#initialize-the-sdk) function, which eventually will return the transfer data after calling a series of chained methods. In this case you'll want to include the ecosystem, as you'll need to retrieve the list of supported assets and chains for the asset you want to transfer. -The process for using `assets` to build the transfer data is as follows: -1. Call the `assets` function and optionally pass in the ecosystem that you want to retrieve a list of assets for or that the asset you want to transfer belongs to. The available ecosystems are: `polkadot`, `kusama`, and `alphanet-relay`. For example: +```js +import { Sdk } from '@moonbeam-network/xcm-sdk'; +import { Ecosystem } from '../../packages/types/build'; + +const sdkInstance = Sdk({ ecosystem: Ecosystem.Polkadot }); +``` + +The chained methods will provide data on the assets and chains along the way, but the final method will return the transfer data. The process of calling the methods is as follows: + +1. Get the list of supported assets for the specified ecosystem ```js - const { assets, asset } = sdkInstance.assets('polkadot'); + const { assets, setAsset } = sdkInstance; ``` - This will return a list of the supported assets and the [`asset`](./reference/methods.md#the-asset-method) function that can be used to define the asset to be transferred - -2. Call the `asset` function and pass in the key or asset object (which includes the key and the origin symbol) to define the asset to be transferred. For example: +2. Call the `setAasset` function and pass in the key or asset object (which includes the key and the origin symbol) to define the asset to be transferred. For example: ```js + import { dot } from '@moonbeam-network/xcm-config'; + // Using the key - const { sourceChains, source } = asset('dot'); + const { sources, setSource } = setAsset(dot); ``` - This will return a list of the supported source chains and the [`source`](./reference/methods.md#the-source-method) function, which is used to define the source chain to transfer the asset from + + This will return a list of the supported source chains for this asset and the [`setSource`]() function, which is used to define the source chain to transfer the asset from -3. Call the `source` function and pass in the key or the chain object (which includes the key, name, and chain type). For example: +3. Call the `setSource` function and pass in the chain object (which includes the key, name, and chain type). For example: ```js - // Using the key - const { destinationChains, destination } = source('polkadot'); + import { polkadot } from '@moonbeam-network/xcm-config'; + + const { destinations, setDestination } = setSource(polkadot); ``` - This will return a list of the supported destination chains where there is an open XCM channel from the source chain for the given asset and the [`destination`](./reference/methods.md#the-destination-method) function, which is used to define the destination chain to transfer the asset to + + This will return a list of the supported destination chains where there is an open XCM channel from the source chain for the given asset and the [`setDestination`](./reference/methods.md#the-destination-method) function, which is used to define the destination chain to transfer the asset to -4. Call the `destination` function and pass in the key or the chain object (which includes the key, name, and chain type). For example: +4. Call the `setDestination` function and pass in the the chain object (which includes the key, name, and chain type). For example: ```js - // Using the key - const { accounts } = destination('moonbeam'); + const { setAddresses } = setDestination(moonbeam); ``` - This will return the [`accounts`](./reference/methods.md#the-accounts-method) function, which is used to define the source and destination addresses and the associated signers for each address + + This will return the [`setAddresses`](./reference/methods.md#the-accounts-method) function, which is used to define the source and destination addresses. The asset and chain objects are managed within the `@moonbeam-network/xcm-config` package. You do not need to directly interact with this package as the SDK exposes this data, but there you can find the list of [assets](https://github.com/moonbeam-foundation/xcm-sdk/blob/main/packages/config/src/assets.ts){target=\_blank} and [chain data](https://github.com/moonbeam-foundation/xcm-sdk/blob/main/packages/config/src/chains.ts){target=\_blank}. An example of the steps described above to build the transfer data to transfer DOT from the Polkadot relay chain to Moonbeam is as follows: ```js +import { dot, moonbeam, polkadot } from '@moonbeam-network/xcm-config'; import { Sdk } from '@moonbeam-network/xcm-sdk'; - -const sdkInstance = Sdk(); +import { Ecosystem } from '../../packages/types/build'; const fromPolkadot = async () => { - const { assets, asset } = sdkInstance.assets(); + const sdkInstance = Sdk({ ecosystem: Ecosystem.Polkadot }); + + const { assets, setAsset } = sdkInstance; + console.log( `The supported assets are: ${assets.map((asset) => asset.originSymbol)}`, ); - const { sourceChains, source } = asset('dot'); + const { sources, setSource } = setAsset(dot); console.log( - `The supported source chains are: ${sourceChains.map( - (chain) => chain.name, - )}`, + `The supported source chains are: ${sources.map((chain) => chain.name)}`, ); - const { destinationChains, destination } = source('polkadot'); + const { destinations, setDestination } = setSource(polkadot); console.log( - `The supported destination chains are: ${destinationChains.map( + `The supported destination chains are: ${destinations.map( (chain) => chain.name, )}`, ); - const { accounts } = destination('moonbeam'); - const data = await accounts( - pair.address, - evmSigner.address, // If using viem, use evmSigner.account.address - { - evmSigner, - polkadotSigner: pair, - }, - ); -}; - -fromPolkadot(); -``` - -!!! note -For more information on each of the `Sdk().assets()` builder functions, including the parameters and returned data, please refer to the [XCM SDK Reference](./reference/methods.md#build-the-transfer-data-starting-with-assets){target=\_blank}. - -If you don't need any of the asset or chain information, you can use the `getTransferData` function: - -```js -import { Sdk } from '@moonbeam-network/xcm-sdk'; - -const sdkInstance = Sdk(); + const { setAddresses } = setDestination(moonbeam); -const fromPolkadot = async () => { - const data = await sdkInstance.getTransferData({ - destinationAddress: evmSigner.address, // If using viem, use evmSigner.account.address - destinationKeyOrChain: 'moonbeam', - keyOrAsset: 'dot', - polkadotSigner: pair, + const transferData = await setAddresses({ sourceAddress: pair.address, - sourceKeyOrChain: 'polkadot', - evmSigner, + destinationAddress: account.address, }); -}; + +} fromPolkadot(); ``` !!! note -For more information on the `Sdk().getTransferData()` function, including the parameters and returned data, please refer to the [XCM SDK Reference](./reference/methods.md#the-get-transfer-data-method){target=\_blank}. + + + + +!!! note + + -As previously mentioned, the same output will be generated regardless of which method you use to build the transfer data. +The same output will be generated regardless of which example you used to build the transfer data. ??? code "Example response" @@ -434,156 +381,473 @@ As previously mentioned, the same output will be generated regardless of which m // data { destination: { - balance: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - }, - chain: l { - ecosystem: 'polkadot', + chain: _EvmParachain { + assets: Map(45) { + "aca": [Object ...], + "astr": [Object ...], + "aseed": [Object ...], + "axlusdc": [Object ...], + "bnc": [Object ...], + "bncs": [Object ...], + "cfg": [Object ...], + "dai": [Object ...], + "ded": [Object ...], + "dot": [Object ...], + "eq": [Object ...], + "eqd": [Object ...], + "fil": [Object ...], + "glmr": [Object ...], + "hdx": [Object ...], + "ibtc": [Object ...], + "intr": [Object ...], + "ldot": [Object ...], + "manta": [Object ...], + "nodl": [Object ...], + "neuro": [Object ...], + "peaq": [Object ...], + "pha": [Object ...], + "pen": [Object ...], + "ring": [Object ...], + "sub": [Object ...], + "usdc": [Object ...], + "usdcwh": [Object ...], + "usdtwh": [Object ...], + "usdt": [Object ...], + "vastr": [Object ...], + "vdot": [Object ...], + "vfil": [Object ...], + "vglmr": [Object ...], + "vmanta": [Object ...], + "wbtc": [Object ...], + "weth": [Object ...], + "ztg": [Object ...], + "pink": [Object ...], + "stink": [Object ...], + "apillon": [Object ...], + "wifd": [Object ...], + "wbtce": [Object ...], + "wethe": [Object ...], + "wstethe": [Object ...], + }, + ecosystem: "polkadot", + explorer: "https://moonbeam.moonscan.io", isTestChain: false, - key: 'moonbeam', - name: 'Moonbeam', - type: 'evm-parachain', - assetsData: [Map], - genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + key: "moonbeam", + name: "Moonbeam", + wh: [Object ...], + checkSovereignAccountBalances: false, + genesisHash: "0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d", + isRelay: false, parachainId: 2004, ss58Format: 1284, usesChainDecimals: false, - weight: 1000000000, - ws: 'wss://wss.api.moonbeam.network', + weight: undefined, + ws: [ "wss://wss.api.moonbeam.network" ], id: 1284, - rpc: 'https://rpc.api.moonbeam.network' + rpc: "https://rpc.api.moonbeam.network", + isEvmSigner: true, + contracts: undefined, + getViemChain: [Function: getViemChain], + nativeAsset: [Getter], + isEqual: [Function: isEqual], + getChainAsset: [Function: getChainAsset], + getWormholeName: [Function: getWormholeName], }, - existentialDeposit: e { - key: 'glmr', - originSymbol: 'GLMR', - amount: 0n, + balance: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: "0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080", + decimals: 10, + ids: [Object ...], + min: undefined, + symbol: undefined, + amount: 17683227925n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], + }, + existentialDeposit: _AssetAmount { + key: "glmr", + originSymbol: "GLMR", + address: "0x0000000000000000000000000000000000000802", decimals: 18, - symbol: 'GLMR' + ids: [Object ...], + min: 100000000000000000n, + symbol: undefined, + amount: 0n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - fee: e { - key: 'dot', - originSymbol: 'DOT', - amount: 33068783n, + fee: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: "0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080", decimals: 10, - symbol: 'DOT' + ids: [Object ...], + min: undefined, + symbol: undefined, + amount: 84005160n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - min: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, + min: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: "0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080", decimals: 10, - symbol: 'DOT' - } + ids: [Object ...], + min: undefined, + symbol: undefined, + amount: 0n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], + }, + sovereignAccountBalances: undefined, }, getEstimate: [Function: getEstimate], - isSwapPossible: true, - max: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, + max: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 18514479903n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - min: e { - key: 'dot', - originSymbol: 'DOT', - amount: 33068783n, + min: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: "0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080", decimals: 10, - symbol: 'DOT' + ids: { + id: "42259045809535163221576417993425387648", + }, + min: undefined, + symbol: undefined, + amount: 84005160n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, source: { - balance: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, + balance: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 29159392703n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - chain: m { - ecosystem: 'polkadot', + chain: _Parachain { + assets: Map(1) { + "dot": [Object ...], + }, + ecosystem: "polkadot", + explorer: undefined, isTestChain: false, - key: 'polkadot', - name: 'Polkadot', - type: 'parachain', - assetsData: Map(0) {}, - genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + key: "polkadot", + name: "Polkadot", + wh: undefined, + checkSovereignAccountBalances: true, + genesisHash: "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3", + isRelay: true, parachainId: 0, ss58Format: 0, usesChainDecimals: false, - weight: 1000000000, - ws: 'wss://rpc.polkadot.io' + weight: undefined, + ws: [ "wss://polkadot-rpc.dwellir.com", "wss://polkadot.api.onfinality.io/public-ws", + "wss://rpc.polkadot.io/" + ], + nativeAsset: [Getter], + isEqual: [Function: isEqual], + getChainAsset: [Function: getChainAsset], + getWormholeName: [Function: getWormholeName], }, - destinationFeeBalance: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, + destinationFee: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 84005160n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - existentialDeposit: e { - key: 'dot', - originSymbol: 'DOT', - amount: 10000000000n, + destinationFeeBalance: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 29159392703n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - fee: e { - key: 'dot', - originSymbol: 'DOT', - amount: 169328990n, + existentialDeposit: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 10000000000n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - feeBalance: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, + fee: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 644912800n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - max: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, + feeBalance: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 29159392703n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], }, - min: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, + max: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' - } + ids: undefined, + min: undefined, + symbol: undefined, + amount: 18514479903n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], + }, + min: _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, + decimals: 10, + ids: undefined, + min: undefined, + symbol: undefined, + amount: 0n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], + }, }, - swap: [AsyncFunction: swap], - transfer: [AsyncFunction: transfer] + transfer: [AsyncFunction: transfer], } ``` -As you may have noticed in the example response, the transfer data contains information on the asset, source, and destination chain. In addition, a few functions have been exposed: +As you may have noticed in the example response, the transfer data contains information on the asset, source, and destination chain. In addition, a couple of functions have been exposed: -- [`swap`](./reference/methods.md#the-swap-method) - returns the transfer data necessary to swap the asset from the destination chain back to the source chain - [`transfer`](./reference/methods.md#the-transfer-method) - transfers a given amount of the asset from the source chain to the destination chain - [`getEstimate`](./reference/methods.md#the-get-estimate-method) - returns an estimated amount of the asset that will be received on the destination chain, less any destination fees ## Transfer an Asset {: #transfer-an-asset } Now that you've built the transfer data, you can transfer the asset from the source chain to the destination chain. To do so, you can use the [`transfer`](./reference/methods.md#the-transfer-method) function, but first, you'll need to specify an amount to send. You can specify the amount in integer or decimal format. For example, if you wanted to send 0.1 DOT, you could use `1000000000n` or `'0.1'`. You can use [asset conversion methods](./reference/methods.md#asset-utilities){target=\_blank}, like [`toDecimal`](./reference/methods.md#the-to-decimal-method) to convert the asset to decimal format. +You'll also need to specify the signer you're using for the transfer. For this example, you can transfer twice the minimum amount required of DOT: ```js ... -const amount = data.min.toDecimal() * 2; -console.log(`Sending from ${data.source.chain.name} amount: ${amount}`); -const hash = await data.transfer(amount); -console.log(`${data.source.chain.name} tx hash: ${hash}`); +const amount = +transferData.min.toDecimal() * 2; +console.log( + `Sending from ${transferData.source.chain.name} amount: ${amount}`, +); +const hash = await transferData.transfer(amount, { + polkadotSigner: pair, +}); +console.log(`${transferData.source.chain.name} tx hash: ${hash}`); ``` As the above snippet shows, the `transfer` function returns a transaction hash on the source chain. @@ -591,162 +855,6 @@ As the above snippet shows, the `transfer` function returns a transaction hash o !!! note For more information on the parameters and returned data for `transfer`, please refer to the [XCM SDK Reference](./reference/methods.md#the-transfer-method){target=\_blank}. -## Swap an Asset {: #swap-an-asset} - -To swap an asset, you can use the same transfer data and call `data.swap()` to switch the source and destination chain information. You can call the `transfer` function to execute the swap from there. - -```js -... - -const swapData = await data.swap(); -const amount = swapData.min.toDecimal() * 2; -console.log(`Sending from ${swapData.source.chain.name} amount: ${amount}`); -const hash = await swapData.transfer(amount); -console.log(`${swapData.source.chain.name} tx hash: ${hash}`); -``` - -The `swap` function returns the transfer data with the original source chain and destination chains swapped. Using the previous example of sending DOT from Polkadot to Moonbeam, the swap transfer data would send DOT from Moonbeam to Polkadot. - -??? code "Example response" - - ```js - // swapData - { - destination: { - balance: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - }, - chain: m { - ecosystem: 'polkadot', - isTestChain: false, - key: 'polkadot', - name: 'Polkadot', - type: 'parachain', - assetsData: Map(0) {}, - genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', - parachainId: 0, - ss58Format: 0, - usesChainDecimals: false, - weight: 1000000000, - ws: 'wss://rpc.polkadot.io' - }, - existentialDeposit: e { - key: 'dot', - originSymbol: 'DOT', - amount: 10000000000n, - decimals: 10, - symbol: 'DOT' - }, - fee: e { - key: 'dot', - originSymbol: 'DOT', - amount: 169328990n, - decimals: 10, - symbol: 'DOT' - }, - feeBalance: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - }, - max: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - }, - min: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - } - }, - getEstimate: [Function: getEstimate], - isSwapPossible: true, - max: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - }, - min: e { - key: 'dot', - originSymbol: 'DOT', - amount: 33068783n, - decimals: 10, - symbol: 'DOT' - }, - source: { - balance: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - }, - chain: l { - ecosystem: 'polkadot', - isTestChain: false, - key: 'moonbeam', - name: 'Moonbeam', - type: 'evm-parachain', - assetsData: [Map], - genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', - parachainId: 2004, - ss58Format: 1284, - usesChainDecimals: false, - weight: 1000000000, - ws: 'wss://wss.api.moonbeam.network', - id: 1284, - rpc: 'https://rpc.api.moonbeam.network' - }, - destinationFeeBalance: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - }, - existentialDeposit: e { - key: 'glmr', - originSymbol: 'GLMR', - amount: 0n, - decimals: 18, - symbol: 'GLMR' - }, - fee: e { - key: 'dot', - originSymbol: 'DOT', - amount: 33068783n, - decimals: 10, - symbol: 'DOT' - }, - min: e { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, - decimals: 10, - symbol: 'DOT' - } - }, - swap: [AsyncFunction: swap], - transfer: [AsyncFunction: transfer] - } - ``` - -!!! note -For more information on the parameters and returned data for `swap`, please refer to the [XCM SDK Reference](./reference/methods.md#the-swap-method){target=\_blank}. - ## Get an Estimate of the Asset to Be Received on the Destination Chain {: #get-estimate } When you send an XCM message, you typically pay fees on the destination chain to execute the XCM instructions. Before you transfer the asset, you can use the [`getEstimate`](./reference/methods.md#the-get-estimate-method) function to calculate an estimated amount of the asset that will be received on the destination chain minus any fees. @@ -759,14 +867,14 @@ You must provide the amount to be transferred to the `getEstimate` function. In ... const amount = '0.1'; -const estimatedAmount = data.getEstimate(amount); +const estimatedAmount = transferData.getEstimate(amount); console.log( `The estimated amount of ${ - data.source.balance.originSymbol + transferData.source.balance.originSymbol } to be received on ${ - data.destination.chain.name - } is: ${estimatedAmount.toDecimal()} ${data.destination.balance.symbol}` + transferData.destination.chain.name + } is: ${estimatedAmount.toDecimal()} ${transferData.destination.balance.getSymbol()}`, ); ``` @@ -776,12 +884,29 @@ The `getEstimate` function returns the estimated amount along with information o ```js // estimatedAmount - { - key: 'dot', - originSymbol: 'DOT', - amount: 966931217n, + _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 915994840n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], } ``` @@ -797,9 +922,9 @@ You can use [transfer data](#build-xcm-transfer-data) to retrieve the minimum an ```js ... - const amount = data.min.toDecimal(); - const symbol = data.min.originSymbol; - + const amount = transferData.min.toDecimal(); + const symbol = transferData.min.getSymbol(); + console.log(`You can send min: ${amount} ${symbol}`); ``` @@ -808,9 +933,9 @@ You can use [transfer data](#build-xcm-transfer-data) to retrieve the minimum an ```js ... - const amount = data.max.toDecimal(); - const symbol = data.max.originSymbol; - + const amount = transferData.max.toDecimal(); + const symbol = transferData.max.getSymbol(); + console.log(`You can send max: ${amount} ${symbol}`); ``` @@ -819,21 +944,57 @@ The `min` and `max` properties return the minimum and maximum amount of the asse ??? code "Example response" ```js - // data.min - { - key: 'dot', - originSymbol: 'DOT', - amount: 33068783n, + // min + _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: "0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080", decimals: 10, - symbol: 'DOT' - } - // data.max - { - key: 'dot', - originSymbol: 'DOT', - amount: 0n, + ids: { + id: "42259045809535163221576417993425387648", + }, + min: undefined, + symbol: undefined, + amount: 84005160n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], + }, + // max + _AssetAmount { + key: "dot", + originSymbol: "DOT", + address: undefined, decimals: 10, - symbol: 'DOT' + ids: undefined, + min: undefined, + symbol: undefined, + amount: 18514479903n, + isSame: [Function: isSame], + isEqual: [Function: isEqual], + copyWith: [Function: copyWith], + convertDecimals: [Function: convertDecimals], + toBig: [Function: toBig], + toBigDecimal: [Function: toBigDecimal], + toDecimal: [Function: toDecimal], + getSymbol: [Function: getSymbol], + getAssetId: [Function: getAssetId], + getBalanceAssetId: [Function: getBalanceAssetId], + getMinAssetId: [Function: getMinAssetId], + getAssetPalletInstance: [Function: getAssetPalletInstance], + getAssetMin: [Function: getAssetMin], + hasOnlyAddress: [Function: hasOnlyAddress], } ``` @@ -846,47 +1007,20 @@ The [transfer data](#build-xcm-transfer-data) provides information on transfer f ```js ... -const sourceChain = data.source.chain.name; -const sourceFee = data.source.fee; +const sourceChain = transferData.source.chain.name; +const sourceFee = transferData.source.fee; -const destinationChain = data.destination.chain.name; -const destinationFee = data.destination.fee; +const destinationChain = transferData.destination.chain.name; +const destinationFee = transferData.destination.fee; console.log( - `You will pay ${sourceFee.toDecimal()} ${ - sourceFee.symbol - } fee on ${ + `You will pay ${sourceFee.toDecimal()} ${sourceFee.getSymbol()} fee on ${ sourceChain - } and ${destinationFee.toDecimal()} ${ - destinationFee.symbol - } fee on ${destinationChain}.` + } and ${destinationFee.toDecimal()} ${destinationFee.getSymbol()} fee on ${destinationChain}.`, ); ``` The `fee` property returns the fees to be paid along with information on the asset. -??? code "Example response" - - ```js - // sourceFee - { - key: 'dot', - originSymbol: 'DOT', - amount: 169328990n, - decimals: 10, - symbol: 'DOT' - } - // destinationFee - { - key: 'dot', - originSymbol: 'DOT', - amount: 33068783n, - decimals: 10, - symbol: 'DOT' - } - ``` - -!!! note -For more information on assets and asset amounts, including fees, please refer to the [XCM SDK Reference](./reference/interfaces.md#assets){target=\_blank}. --8<-- 'text/third-party-content.md'