jcc-ethereum-utils v0.2.7
jcc-ethereum-utils
Toolkit of crossing chain from EVM networks to SWTC chain.
Description
Transfer token automatically from Ethereum to SWTC chain. Support ether and erc20 tokens.
e.g. you transfer 1 eth to Ethereum Fingate from your ethereum address, If success the contract will automatically transfer 1 jeth 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-ethereum-utilsCDN
jcc_ethereum_utils as a global variable.
<script src="https://unpkg.com/jcc-ethereum-utils/dist/jcc-ethereum-utils.min.js"></script>Usage
Breaking changes since 0.1.4, if you used 0.1.3 see this demo.
// demo
import { Fingate, Ethereum, ERC20 } from "jcc-ethereum-utils";
// Ethereum node
const node = "https://eth626892d.jccdex.cn";
// Your ethereum secret
const ethereumSecret = "";
// Your ethereum address
const ethereumAddress = "";
// Your swtc address
const swtcAddress = "";
// Deposit amount
const amount = "1";
// Ethereum fingate contract address, don't change it.
const scAddress = "0x3907acb4c1818adf72d965c08e0a79af16e7ffb8";
try {
  // deposit 1 ETH
  const ethereumInstance = new Ethereum(node);
  ethereumInstance.initWeb3();
  const fingateInstance = new Fingate();
  fingateInstance.init(scAddress, ethereumInstance);
  // Check if has pending order, if has don't call the next deposit api
  const state = await fingateInstance.depositState(ethereumAddress);
  if (fingateInstance.isPending(state)) {
    return;
  }
  // start to transfer 1 ETH to fingate address
  const hash = await fingateInstance.deposit(ethereumSecret, swtcAddress, amount);
  console.log(hash);
} catch (error) {
  console.log(error);
}
// deposit erc20 token
try {
  // deposit 1 JCC
  // JCC contract address
  const jccContractAddress = "0x9BD4810a407812042F938d2f69f673843301cfa6";
  const ethereumInstance = new Ethereum(node);
  ethereumInstance.initWeb3();
  const erc20Instance = new ERC20();
  erc20Instance.init(jccContractAddress, ethereumInstance);
  const fingateInstance = new Fingate();
  fingateInstance.init(scAddress, ethereumInstance);
  fingateInstance.initErc20(erc20Instance);
  // Check if has pending order, if has don't call depositErc20 api
  const state = await fingateInstance.depositState(address, jccContractAddress);
  if (fingateInstance.isPending(state)) {
    return;
  }
  const amount = "1";
  const receipts = await fingateInstance.depositErc20(ethereumSecret, swtcAddress, amount);
  console.log(receipts);
} catch (error) {
  console.log(error);
}API
see API.md
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago