npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eth-merkle-bridge-js

v0.3.1

Published

Ethereum <-> Aergo Merkle Bridge JS SDK

Downloads

245

Readme

eth-merkle-bridge-js

JS SDK for Ethereum <-> Aergo Merkle bridge.

Quick start

npm i eth-merkle-bridge-js

Send Aergo ERC20 tokens by locking on Ethereum and Unfreezing on Aergo.

import {ethToAergo as eta} from 'eth-merkle-bridge-js';
import Web3 from 'web3';
import { AergoClient } from '@herajs/client';

// get providers to connect with networks
let web3 = new Web3(window.ethereum);
let accountId = await ethereum.enable();
web3.eth.defaultAccount = accountId[0];
let hera = new AergoClient(); // connect to localhost:7845 by default

// arguments
const bridgeEthAddr = "0x89eD1D1C145F6bF3A7e62d2B8eB0e1Bf15Cb2374";
const bridgeAergoAddr = "AmgQqVWX3JADRBEVkVCM4CyWdoeXuumeYGGJJxEeoAukRC26hxmw";
const aergoErc20Addr = "0xd898383A12CDE0eDF7642F7dD4D7006FdE5c433e";
const receiverAergoAddr = "AmNMFbiVsqy6vg4njsTjgy7bKPFHFYhLV4rzQyrENUS9AM1e3tw5";
const amount = "10000000000000000000" // 10 aergoErc20 with 18 decimals
let bridgeAergoAbi 
(async () => { bridgeAergoAbi = await hera.getABI(bridgeAergoAddr) })();


// LOCK TOKENS
// send any ERC20 from Ethereum to Aergo
const receipt = await eta.increaseApproval(
    web3, bridgeEthAddr, amount, aergoErc20Addr, erc20Abi);
const receipt = await eta.lock(
    web3, receiverAergoAddr, aergoErc20Addr, amount, bridgeEthAddr, 
    bridgeEthAbi
);

// Check unfreezable and pending balances
let [unfreezable, pending] = await eta.unfreezable(
    web3, hera, bridgeEthAddr, bridgeAergoAddr,
    receiverAergoAddr, aergoErc20Addr
);

// UNFREEZE TOKENS
// get aergo connect signer
const signer = await aergoConnectCall(
    'ACTIVE_ACCOUNT', 'AERGO_ACTIVE_ACCOUNT', {});
const txSender = signer.account.address;

// build unfreeze tx params
// metamask web3.eth provider doesn't implement getProof so use custom provider to query
let blockoWeb3 = new Web3("http://localhost:8545");
let builtTx = await eta.buildUnfreezeTx(
    blockoWeb3, hera, txSender, bridgeEthAddr, bridgeAergoAddr,
    bridgeAergoAbi, receiverAergoAddr, aergoErc20Addr
);
builtTx.to = bridgeAergoAddr;
builtTx.payload_json = JSON.parse(builtTx.payload);
delete builtTx.payload

// send built tx with aergo connect
const tx = await aergoConnectCall(
    'SEND_TX', 'AERGO_SEND_TX_RESULT', builtTx);
// then get tx receipt with tx.hash

Documentation

Aergo ERC20

Send aergo ERC20 from Ethereum to Aergo
  • ethToAergo.increaseApproval()
  • ethToAergo.lock()
  • ethToAergo.unfreezable()
  • ethToAergo.buildUnfreezeTx()
Send native(unfreezed) aergo from Aergo back to Ethereum (Erc20 form)
  • aergoToEth.buildFreezeTx()
  • aergoToEth.unlockable()
  • aergoToEth.unlock()

Other ERC20 tokens

Send ERC20 from Ethereum to Aergo
  • ethToAergo.increaseApproval()
  • ethToAergo.lock()
  • ethToAergo.mintable()
  • ethToAergo.buildMintTx()
Send minted token from Aergo back to Ethereum (Erc20 form)
  • aergoToEth.buildBurnTx()
  • aergoToEth.unlockable()
  • aergoToEth.unlock()

ARC1 Aergo native tokens

  • TODO

Utils

  • utils.getEthAnchorStatus()
  • utils.getAergoAnchorStatus()

Contribute

Setup

npm install

Test

npm test