Package Exports
- jcc-moac-utils
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 (jcc-moac-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
jcc-moac-utils
Toolkit of crossing chain from MOAC chain to SWTC chain.
Description
Transfer token automatically from MOAC chain to SWTC chain. Support moac and erc20 tokens.
e.g. you transfer 1 moac
to Moac Fingate from your moac address, If success the contract will automatically transfer 0.999 jmoac
(if the transaction fee is 0.001 moac
) to your swtc address from Jingtum Fingate in a few minutes.
Support token list of erc20
If you wanna we support other erc20 token, please contact us.
Installtion
npm i jcc-moac-utils
Usage
// demo
import { MoacFingate, Erc20Fingate } from "jcc-moac-utils";
// Moac node
const node = 'https://moac1ma17f1.jccdex.cn';
// Production network or not
const production = true;
// Your moac secret
const moacSecret = '';
// Your moac address
const moacAddress = '';
// Your swtc address
const swtcAddress = '';
// Deposit amount
const amount = 1;
// Moac fingate contract address, don't change it.
const scAddress = '0x66c9b619215db959ec137ede6b96f3fa6fd35a8a';
try {
// deposit 1 MOAC
const inst = new MoacFingate(node, production);
inst.initMoacContract(scAddress);
// Check if has pending order, if has don't call the next deposit api
const state = await inst.depositState(moacAddress);
if (inst.isPending(state)) {
return;
}
// start to transfer 1 MOAC to fingate address
const hash = await inst.deposit(swtcAddress, amount, moacSecret);
console.log(hash);
} catch (error) {
console.log(error);
}
// deposit erc20 token
try {
// deposit 1 CKM
// CKM contract address
const ckmContractAddress = "0x4d206d18fd036423aa74815511904a2a40e25fb1";
const inst = new Erc20Fingate(node, production);
inst.initErc20Contract(scAddress, ckmContractAddress);
// Check if has pending order, if has don't call transfer api
const state = await inst.depositState(moacAddress, ckmContractAddress);
if (inst.isPending(state)) {
return;
}
// The first step to transfer 1 CKM to fingate address.
const transferHash = await inst.transfer(amount, moacSecret);
// The next step to submit previous transfer hash.
const depositHash = await inst.depositToken(swtcAddress, amount, transferHash, moacSecret);
console.log(depositHash);
// Warning:
// This is not an atomic operating to deposit erc20 tokens for now,
// If the first step is successful but next step is failed, please contact us.
// The next version will make it an atomic operating after the next version of solidity contract upgrade.
} catch (error) {
console.log(error);
}