Links

Methods

Dive into the specifics of each API methods by checking out our complete documentation.

Account

First, we create Keyring which you can think of as a store that saves the key-pair. The nice thing about Keyring is that it keeps private key not being exposed to the code but one can still sign a transaction.
import { Keyring } from '@polkadot/keyring';
const keyring = new Keyring({type: 'sr25519'});
const PHRASE = 'entire material egg meadow latin bargain dutch coral blood melt acoustic thought';
const account: KeyringPair = keyring.addFromMnemonic(PHRASE);
// KeyringPair is an object and has the ADDRESS field
console.log("Your address is: ", account.address)

Instances

Mainnet

const MAINNET_1 = 'wss://mangata-x.api.onfinality.io/public-ws'
const MAINNET_2 = 'wss://prod-kusama-collator-01.mangatafinance.cloud'

Testnet

const TESTNET = 'wss://roccoco-testnet-collator-01.mangatafinance.cloud'

Get Api

If you need to retrieve underlying API
import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
const api = await mangata.getApi()
console.log("Connected: ", api.isConnected)

Get Chain

If you need to retrieve the chain name
import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
const chain = await mangata.getChain()
console.log('Chain: ', chain)

Send Kusama Tokens from Relay to Parachain

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
const ksmAccount: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic to send Kusama token to Mangata parachain
* @param {string} kusamaEndpoint
* @param {string | Keyringpair} ksmAccount
* @param {string} mangataDestinationAddress
* @param {BN} amount (KSM is 12 decimals => 1 KSM = 1_000_000_000_000)
* @param {number} parachainID (by default it is set to 2110)
* @param {TxOptions} [txOptions]
*/
await mangata.sendKusamaTokenFromRelayToParachain(
'wss://kusama-rpc.polkadot.io',
ksmAccount,
'5lolMojZ6yPgeoKmzsJ9TLA4hXc8ANdV2nBpgyusuwPQJ9qq',
new BN('10000000000000'), // 10 ksm
2110,
)

Send Kusama Token From Parachain To Relay

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
const mangataAccount: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic to send Kusama token to Mangata parachain
* @param {string | Keyringpair} mangataAccount
* @param {string} destinationKusamaAddress
* @param {BN} amount (KSM is 12 decimals => 1 KSM = 1_000_000_000_000)
* @param {TxOptions} [txOptions]
*/
await mangata.sendKusamaTokenFromParachainToRelay(
mangataAccount,
'DMpxJpK8n1Tw2ND6UCV6fmgRLiHrjxhtuCugiwpPAskpE1X',
new BN('10000000000000'), // 10 ksm
)

Create Pool

Extrinsic to create pool
import { Mangata, MangataGenericEvent } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
// Look at the page Account how to create KeyringPair
const account: KeyringPair = keyring.addFromMnemonic(mnemonic);
// maybe you will need to unlock with the password
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic to create pool
* @param {string | Keyringpair} account
* @param {string} firstTokenId
* @param {BN} firstTokenAmount
* @param {string} secondTokenId
* @param {BN} secondTokenAmount
* @param {TxOptions} [txOptions]
*/
await mangata.createPool(
account,
'0', // Token Id 0 is MGX
new BN(1000000000000000000000), // 1000 MGX (MGX is 18 decimals)
'4', // Token Id 4 is KSM
new BN(1000000000000), // 1 KSM (KSM is 12 decimals)
{
statusCallback: (result) => {
// result is of the form ISubmittableResult
console.log(result)
},
extrinsicStatus: (result) => {
// result is of the form MangataGenericEvent[]
for (let index = 0; index < result.length; index++) {
console.log('Phase', result[index].phase.toString())
console.log('Section', result[index].section)
console.log('Method', result[index].method)
console.log('Documentation', result[index].metaDocumentation)
}
},
}
)

Buy Asset

import { Mangata, MangataGenericEvent } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
// Look at the page Account how to create KeyringPair
const account: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic to buy/swap bought token id in bought token amount for sold token id, while
* specifying max amount in: maximal amount you are willing to pay in sold token id to
* purchase bought token id in bought token amount.
*
* @param {string | Keyringpair} account
* @param {string} soldAssetId
* @param {string} boughtAssetId
* @param {BN} amount
* @param {BN} maxAmountIn
* @param {TxOptions} [txOptions]
*/
await mangata.buyAsset(
account,
'0', // Token Id 0 is MGX
'4', // Token Id 4 is KSM
new BN(1000000000000000000000), // 1000 MGX (MGX is 18 decimals)
new BN(1000000000000), // 1 KSM (KSM is 12 decimals)
{
statusCallback: (result) => {
// result is of the form ISubmittableResult
console.log(result)
},
extrinsicStatus: (result) => {
// result is of the form MangataGenericEvent[]
for (let index = 0; index < result.length; index++) {
console.log('Phase', result[index].phase.toString())
console.log('Section', result[index].section)
console.log('Method', result[index].method)
console.log('Documentation', result[index].metaDocumentation)
}
},
}
)

Sell Asset

import { Mangata, MangataGenericEvent } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
// Look at the page Account how to create KeyringPair
const account: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic to sell/swap sold token id in sold token amount for bought token id,
* while specifying min amount out: minimal expected bought token amount
*
* @param {string | Keyringpair} account
* @param {string} soldAssetId
* @param {string} boughtAssetId
* @param {BN} amount
* @param {BN} minAmountOut
* @param {TxOptions} [txOptions]
*/
await mangata.sellAsset(
account,
'0', // Token Id 0 is MGX
'4', // Token Id 4 is KSM
new BN(1000000000000000000000), // 1000 MGX (MGX is 18 decimals)
new BN(1000000000000), // 1 KSM (KSM is 12 decimals)
{
statusCallback: (result) => {
// result is of the form ISubmittableResult
console.log(result)
},
extrinsicStatus: (result) => {
// result is of the form MangataGenericEvent[]
for (let index = 0; index < result.length; index++) {
console.log('Phase', result[index].phase.toString())
console.log('Section', result[index].section)
console.log('Method', result[index].method)
console.log('Documentation', result[index].metaDocumentation)
}
},
}
)

Mint Liquidity

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
// Look at the page Account how to create KeyringPair
const account: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic to add liquidity to pool, while specifying first token id
* and second token id and first token amount. Second token amount is calculated in block, but cannot
* exceed expected second token amount
*
* @param {string | Keyringpair} account
* @param {string} firstTokenId
* @param {string} secondTokenId
* @param {BN} firstTokenAmount
* @param {BN} expectedSecondTokenAmount
* @param {TxOptions} [txOptions]
*/
await mangata.mintLiquidity(
account,
'0', // Token Id 0 is MGX
'4', // Token Id 4 is KSM
new BN(1000000000000000000000), // 1000 MGX (MGX is 18 decimals)
new BN(1000000000000), // 1 KSM (KSM is 12 decimals)
{
statusCallback: (result) => {
// result is of the form ISubmittableResult
console.log(result)
},
extrinsicStatus: (result) => {
// result is of the form MangataGenericEvent[]
for (let index = 0; index < result.length; index++) {
console.log('Phase', result[index].phase.toString())
console.log('Section', result[index].section)
console.log('Method', result[index].method)
console.log('Documentation', result[index].metaDocumentation)
}
},
}
)

Burn Liquidity

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
// Look at the page Account how to create KeyringPair
const account: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic to remove liquidity from liquidity pool, specifying first token id and
* second token id of a pool and liquidity token amount you wish to burn
*
* @param {string | Keyringpair} account
* @param {string} firstTokenId
* @param {string} secondTokenId
* @param {BN} liquidityTokenAmount
* @param {TxOptions} [txOptions]
*/
await mangataInstance.burnLiquidity(
account,
'0', // Token Id 0 is MGX
'4', // Token Id 4 is KSM
new BN(100000000000000000000),
{
statusCallback: (result) => {
// result is of the form ISubmittableResult
console.log(result)
},
extrinsicStatus: (result) => {
// result is of the form MangataGenericEvent[]
for (let index = 0; index < result.length; index++) {
console.log('Phase', result[index].phase.toString())
console.log('Section', result[index].section)
console.log('Method', result[index].method)
console.log('Documentation', result[index].metaDocumentation)
}
},
}
)

Calculate Buy Price

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns sell amount you need to pay in sold token id for bought token id in buy
* amount, while specifying input reserve – reserve of sold token id, and output reserve
* – reserve of bought token id
*
* @param {BN} inputReserve
* @param {BN} outputReserve
* @param {BN} buyAmount
*
* @returns {BN}
*/
const buyPrice = await mangata.calculateBuyPrice(
new BN(100000000000000000000000), // 100000
new BN(20000000000000000000000), // 20000
new BN(1000000000000000000) // 1
)
console.log("Buy Price: ", buyPrice.toString())

Calculate Sell Price

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns bought token amount returned by selling sold token id for bought token id in
* sell amount, while specifying input reserve – reserve of sold token id, and output
* reserve – reserve of bought token id
*
* @param {BN} inputReserve
* @param {BN} outputReserve
* @param {BN} sellAmount
*
* @returns {BN}
*/
const sellPrice = await mangata.calculateSellPrice(
new BN(100000000000000000000000), // 100000
new BN(20000000000000000000000), // 20000
new BN(1000000000000000000) // 1
)
console.log("Sell Price: ", sellPrice.toString())

Get Burn Amount

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns bought token amount returned by selling sold token id for bought token id in
* sell amount, while specifying input reserve – reserve of sold token id, and output
* reserve – reserve of bought token id
*
* @param {BN} inputReserve
* @param {BN} outputReserve
* @param {BN} sellAmount
*
* @returns {BN}
*/
const result = await mangata.getBurnAmount('0', '4', new BN(1000000000000000000000))

Get Amount of Token in Pool

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns amount of token ids in pool.
*
* @param {string} firstTokenId
* @param {string} secondTokenId
*
* @returns {BN | Array}
*/
const balance = await mangata.getAmountOfTokenIdInPool('0', '4')

Get Liquidity Asset Id

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns liquidity asset id while specifying first and second Token Id.
* Returns same liquidity asset id when specifying other way
* around – second and first Token Id
*
* @param {string} firstTokenId
* @param {string} secondTokenId
*
* @returns {BN}
*/
const liquidityAssetId = await mangata.getLiquidityAssetId('0', '4')

Get Liquidity Pool

import { Mangata } from '@mangata-finance/sdk'
import { BN } from '@polkadot/util'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns pool corresponding to specified liquidity asset ID
* @param {string} liquidityAssetId
*
* @returns {BN | Array}
*/
const pool = await mangata.getLiquidityPool('1')

Transfer Token

import { Mangata } from '@mangata-finance/sdk'
import { KeyringPair } from '@polkadot/keyring/types'
import { BN } from '@polkadot/util'
// Look at the Account how to create KeyringPair
const account: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic that transfers Token Id in value amount from origin to destination
* @param {string | Keyringpair} account
* @param {string} tokenId
* @param {string} address
* @param {BN} amount
* @param {TxOptions} [txOptions]
*
* @returns {(MangataGenericEvent|Array)}
*/
await mangata.transferToken(
account,
'4', // TokenID 4 is KSM
account.address,
new BN(100000000000000), // 100 KSM (KSM is 12 decimals)
{
statusCallback: (result) => {
// result is of the form ISubmittableResult
console.log(result)
},
extrinsicStatus: (result) => {
// result is of the form MangataGenericEvent[]
for (let index = 0; index < result.length; index++) {
console.log('Phase', result[index].phase.toString())
console.log('Section', result[index].section)
console.log('Method', result[index].method)
console.log('Documentation', result[index].metaDocumentation)
}
},
}
)

Transfer Token All

import { Mangata } from '@mangata-finance/sdk'
import { KeyringPair } from '@polkadot/keyring/types'
// Look at the Account how to create KeyringPair
const account: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Extrinsic that transfers all token Id from origin to destination
* @param {string | Keyringpair} account
* @param {string} tokenId
* @param {string} address
* @param {TxOptions} [txOptions]
*
* @returns {(MangataGenericEvent|Array)}
*/
await mangata.transferTokenAll(
account,
'4',
account.address,
{
statusCallback: (result) => {
// result is of the form ISubmittableResult
console.log(result)
},
extrinsicStatus: (result) => {
// result is of the form MangataGenericEvent[]
for (let index = 0; index < result.length; index++) {
console.log('Phase', result[index].phase.toString())
console.log('Section', result[index].section)
console.log('Method', result[index].method)
console.log('Documentation', result[index].metaDocumentation)
}
},
}
)

Get Total Issuance

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns total issuance of Token Id
* @param {string} tokenId
*
* @returns {BN}
*/
const issuance = await mangata.getTotalIssuance('4')

Get Token Balance

import { Mangata } from '@mangata-finance/sdk'
import { KeyringPair } from '@polkadot/keyring/types'
// Look at the Account how to create KeyringPair
const account: KeyringPair = keyring.addFromMnemonic(mnemonic);
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns token balance for address
* @param {string} tokenId
* @param {string} address
*
* @returns {TokenBalance}
*/
const tokenBalance = await mangata.getTokenBalance('0', account.address)

Get Token Info

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns token info
* @param {string} tokenId
*
* @returns {TTokenInfo}
*/
const tokenInfo = await mangata.getTokenInfo('0')

Get Liquidity Token Ids

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns liquditity token Ids
* @returns {string | Array}
*/
const liquidityTokenIds = await mangata.getLiquidityTokenIds()

Get Pools

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns all the pools
* @returns {TPoolWithRatio | Array}
*/
const pools = await mangata.getPools()

Get Invested Pools

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns all the pools for the specified address
* @param {string} address
* @returns {TPoolWithShare | Array}
*/
const investedPools = await mangata.getInvestedPools("5lolMojZ6yPgeoKmzsJ9TLA4hXc8ANdV2nBpgyusuwPQJ9qq")

Get Liquidity Tokens

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns all the liquidity tokens
* @returns {TMainTokens}
*/
const liquidityTokens = await mangata.getLiquidityTokens()

Get Balances

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns all the balances from the node for each token Id
* @returns { TBalances }
*/
const balances = await mangata.getBalances()

Get Assets Info

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns info about all assets
* @returns { TMainTokens }
*/
const assets = await mangata.getAssetsInfo()

Get Owned Tokens

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns owned tokens for the specific address
* @param {string} address
* @returns { Record<TTokenId, TToken> | null }
*/
const tokens = await mangata.getOwnedTokens("5lolMojZ6yPgeoKmzsJ9TLA4hXc8ANdV2nBpgyusuwPQJ9qq")

Get Block Number

import { Mangata } from '@mangata-finance/sdk'
const mangata = Mangata.getInstance([MAINNET_1, MAINNET_2])
/**
* Returns the latest block number
* @returns { BN }
*/
const blockNumber = await mangata.getBlockNumber()
Last modified 2mo ago