0.2.7 • Published 3 years ago

jcc-ethereum-utils v0.2.7

Weekly downloads
21
License
Apache-2.0
Repository
github
Last release
3 years ago

jcc-ethereum-utils

Toolkit of crossing chain from EVM networks to SWTC chain.

npm Build Status Coverage Status Dependencies npm downloads PRs Welcome

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-utils

CDN

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

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.13

4 years ago

0.1.14

4 years ago

0.2.0

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago