Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@moonbeam-network/xcm-sdk

Package Overview
Dependencies
Maintainers
4
Versions
367
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moonbeam-network/xcm-sdk

Easy way to transfer assets from Moonbeam, Moonriver, Moonbase to other parachains and back

  • 0.0.1-dev.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
304
increased by26.67%
Maintainers
4
Weekly downloads
 
Created
Source

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();

// Optionally you can provide signers or do it on get()
const { moonbeam } = init({
  ethersSigner,
  polkadotSigner,
});

Accounts

const moonbeamAddress = '0xeF46c7649270C912704fB09B75097f6E32208b85';
const substrateAddress = '5DG5Fn3ww3KPza1RLoap6QJNzQfEvRebxypDGp35YuMX5y2K';

Deposit

// moonbeam.symbols is a list of asset symbols that you can deposit/withdraw
// chains is a list of chains from which you can deposit asset
const { chains, from } = moonbeam.deposit(moonbeam.symbols[0]);

const { min, send } = await from(chains[0]).get(
  moonbeamAddress,
  substrateAddress,
  // if you haven't provided on init
  { 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,
  // if you haven't provided on init
  { ethersSigner },
);

await send(min, (event) => console.log(event));

Get balances

const unsubscribe = await moonbeam.subscribeToAssetsBalanceInfo(
  moonbeamAddress,
  (balances) => {
    balances.forEach(({ asset, balance, origin }) => {
      // xcDOT: 0.073742 (Polkadot DOT)
      // ...
      console.log(
        `${balance.symbol}: ${toDecimal(balance.balance, balance.decimals)} (${
          origin.name
        } ${asset.originSymbol})`,
      );
    });
  },
);

unsubscribe();

Examples

  • simple
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

Keywords

FAQs

Package last updated on 26 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc