Package Exports
- xcm-sdk
- xcm-sdk/lib.esm/index.js
- xcm-sdk/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (xcm-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
XCM SDK
About
XCM SDK is a tool that provides an interface to send XCM messages for Substrate based blockchains. This library is written in Typescript so it can be imported in a whole new set of applications or dApps that use Javascript/Typescript engines such as Node.js.
Get Started
Install
npm i xcm-sdk
Usage
// JavaScript
const { Provider } = require("xcm-sdk")
// TypeScript
import { Provider } from "xcm-sdk"
Provider
const provider = new Provider(rpc, sender)
Param | Description |
---|---|
rpc | rpc endpoint |
sender | signer of the transaction |
Examples
If you want to sign with Alice in a local node:
const rpc = "ws://127.0.0.1:37345"
await cryptoWaitReady();
const keyring = new Keyring({ type: "sr25519" });
const sender = keyring.addFromUri("//Alice");
const provider = new Provider(rpc, sender);
If you want to sign with mnemonic
const sender = keyring.addFromMnemonic(
"<your mnemonic seed here>"
);
Supported Methods
Reserve Asset Transfer with reserveTransferAsset and LimitedReserveTransferAsset methods and Asset teleportation with teleportAsset and LimitedTeleportAsset methods.
provider.limitedReserveTransferAssets(params)
provider.reserveTransferAssets(params)
provider.limitedReserveTransferAssets(params)
provider.reserveTransferAssets(params)
Methods parameters
Param | Description |
---|---|
destination | The destination to transfer the asset. If you want to transfer asset from relaychain to a parachain set 'Parachain'. Default 'Here'. |
destinationParents | 0 is default, 1 when you want to transfer from parachain to relaychain or parachain to parachain |
destinationValue | The destination value, for example a parachain id |
beneficiary | beneficary target, an accountId32 |
beneficiaryParents | 0 is default |
beneficiaryValue | The beneficiary value, account address to send the asset |
amount | token amount to transfer |
assetId | AssetId to transfer from parachain, make sure the parchain support the asset and the sender account have enough asset to transfer |
weightLimit | Optional, only for limited methods. Set the maximum weight for the extrinsic |
Disclaimer
Depends on the parachain or relay chain configuration you have to use Asset teleportation or reserve asset transfer. Make sure you know what method use before execute any transfer. You can search in any scan to know, for example rococo scan
Rococo examples
If you want to tests in Testnet, you have Rococo. Get some assets: Rococo faucet
Send Asset from Rococo to Rockmine
const destination = "Parachain"
const destinationValue = 2000 // Rockmine parchain id
const beneficiary = "AccountId32"
const beneficiaryValue = "<rockmine account address>" // account address
const amount = 1000000000000000
const res = await provider.limitedTeleportAssets({
destination,
destinationValue,
beneficiary,
beneficiaryValue,
amount,
});
Send Asset from RockMine to Rococo
const destinationParents = 1; // Destination to Rococo
const beneficiary = "AccountId32"
const beneficiaryValue = "<rococo account address>" // account address
const amount = 1000000000000000
const res = await provider.limitedTeleportAssets({
destination,
destinationValue,
beneficiary,
beneficiaryValue,
amount,
});
Send native Asset (ROC) from RockMine to Dali
const destination = "Parachain";
const destinationValue = 2087; // dali parachain id
const destinationParents = 1;
const beneficiary = "AccountId32";
const beneficiaryValue = "<dali account address>";
const assetParents = 1; // native asset (ROC)
const amount = 1000000000000000;
const res = await provider.limitedReserveTransferAssets({
destination,
destinationValue,
destinationParents,
beneficiary,
beneficiaryValue,
assetParents,
amount,
});
Send Asset from Rococo to dali
const destination = "Parachain";
const destinationValue = 2087;
const beneficiary = "AccountId32";
const beneficiaryValue = "<dali account address>";
const amount = 1000000000000000;
const res = await provider.limitedReserveTransferAssets({
destination,
destinationValue,
beneficiary,
beneficiaryValue,
amount,
});
Testing
Running the unit tests.
npm run test
Running the test coverage.
npm run test:cov
Change Log
See Changelog for more information.
Contributing
Contributions welcome! See Contributing.
Collaborators
License
Licensed under the MIT - see the LICENSE file for details.