XCM-SDK
:warning: This package is not production ready and is in heavy development!
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 packages/sdk/examples/simple/
npm i
// edit index.ts by adding your accounts
npm start