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.
Core Methods
The SDK provides the following core methods:
Method | Description |
---|---|
init() |
Initializes the XCM SDK. Must be called first before any other SDK methods |
deposit() |
Initiates a deposit to transfer assets from another chain to Moonbeam |
withdraw() |
Initiates a withdraw to transfer assets from Moonbeam to another chain |
subscribeToAssetsBalanceInfo() |
Listens for balance changes for a given account for each of the supported assets |
isXcmSdkDeposit() |
Returns a boolean indicating whether the given transfer data is for a deposit or not |
isXcmSdkWithdraw() |
Returns a boolean indicating whether the given transfer data is for a withdraw or not |
toDecimal() |
Returns a given balance in decimal format |
toBigInt() |
Returns a given decimal in BigInt format |
Deposit Methods
When building the transfer data needed for a deposit, you'll use multiple methods to build the underlying XCM message and send it:
Method | Description |
---|---|
deposit() |
Initiates a deposit to transfer assets from another chain to Moonbeam |
from() |
Sets the source chain where the deposit will originate from. This function is returned from the deposit() function. Must call deposit() first |
get() |
Sets the account on Moonbeam to deposit the funds to and the source account where the deposit will be sent from. This function is returned from the from() function. Must call from() first |
send() |
Sends the deposit transfer data given an amount to send. This function is returned from the get() function. Must call get() first |
getFee() |
Returns an estimate of the fee for transferring a given amount, which will be paid in the asset specified in the deposit() function. This function is returned from the get() function. Must call get() first |
Withdraw Methods
When building the transfer data needed for a withdraw, you'll use multiple methods to build the underlying XCM message and send it:
Method | Description |
---|---|
withdraw() |
Initiates a withdraw to transfer assets from Moonbeam to another chain |
to() |
Sets the destination chain where the assets will be withdrawn to. This function is returned from the withdraw() function. Must call withdraw() first |
get() |
Sets the account on the destination chain to send the withdrawn funds to. This function is returned from the to() function. Must call to() first |
send() |
Sends the withdraw transfer data given an amount to send. This function is returned from the get() function. Must call get() first |
getFee() |
Returns an estimate of the fee for transferring a given amount, which will be paid in the asset specified in the withdraw() function. This function is returned from the get() function. Must call get() first |