The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem. With the SDK, you don't need to worry about determining the multilocation of the origin or destination assets or which extrinsics are used on which networks to send XCM transfers. To deposit or withdraw assets, you simply define the asset and origin chain you want to deposit from or withdraw back to, along with the sending account's signer, and the amount to send.
Documentation
Installation
npm i @moonbeam-network/xcm-config @moonbeam-network/xcm-sdk
Usage
Init
import { init } from '@moonbeam-network/xcm-sdk';
const { moonbeam } = init();
const { moonbeam } = init({
ethersSigner,
polkadotSigner,
});
Accounts
const moonbeamAddress = '0xeF46c7649270C912704fB09B75097f6E32208b85';
const substrateAddress = '5DG5Fn3ww3KPza1RLoap6QJNzQfEvRebxypDGp35YuMX5y2K';
Deposit
const { chains, from } = moonbeam.deposit(moonbeam.symbols[0]);
const { min, send } = await from(chains[0]).get(
moonbeamAddress,
substrateAddress,
{ polkadotSigner },
);
await send(min, (event) => console.log(event));
Withdraw
const { chains, to } = moonbeam.withdraw(moonbeam.symbols[0]);
const { min, send } = await to(chains[0]).get(
substrateAddress,
{ ethersSigner },
);
await send(min, (event) => console.log(event));
Get balances
const unsubscribe = await moonbeam.subscribeToAssetsBalanceInfo(
moonbeamAddress,
(balances) => {
balances.forEach(({ asset, balance, origin }) => {
console.log(
`${balance.symbol}: ${toDecimal(balance.balance, balance.decimals)} (${
origin.name
} ${asset.originSymbol})`,
);
});
},
);
unsubscribe();
Examples
git clone git@github.com:PureStake/xcm-sdk.git
cd xcm-sdk
npm i
cd examples/sdk-simple
npm start
Contributing
git clone git@github.com:PureStake/xcm-sdk.git
npm i
npm run dev
Tests
Unit tests
npm run test
Acceptance tests
cp .env.example .env
npm run test:acc