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

wbgl-bridge-sdk

v5.0.5

Published

A wrapper around the WBGL<->BGL Bitgesell Bridge

Downloads

11

Readme

Bitgesell WBGLBridge SDK

This is a wrapper around the WBGL bridge for use on the Nodejs backend and Browsers written in TypeScript.

NB: To access the Bridge, we recommend visiting the official bridge at bglswap.com

Table of Contents

Installation

To get started with the Bitgesell WGL Bridge SDK, you can install it using npm:

npm install wbgl-bridge-sdk

or using yarn:

yarn add wbgl-bridge-sdk

Usage

Import the SDK into your TypeScript project to start using the Bitgesell WGL Bridge functionalities:

Initialization

import { ethers } from 'ethers'

import {
  ChaindIds,
  ChainNames,
  IBridgeConfig,
  WBGLBridgeSDK
  BGLWBGLExchangePair,
  WBGLBGLExchangePair,
} from 'wbgl-bridge-sdk'

  const bscProvider = 'https://rpc.ankr.com/bsc'
  const provider = new ethers.providers.JsonRpcProvider(bscProvider)
  const evmPrivateKey = process.env.EVM_PRIVATE_KEY
  const signer = new ethers.Wallet(evmPrivateKey, provider)
  const bnbAddress = await signer.getAddress()


const config: IBridgeConfig = {
  evmPrivateKey: evmPrivateKey, // Arbitrum, BNB chain, Ethereum privateKey etc
    provider: provider,
    chainName: ChainNames.Ethereum,
    chainId: ChaindIds.Ethereum,
    bridgeEndpoint: 'https://bglswap.com/app/',
    bglPrivateKeyOrSeed: process.env.BGL_PRIVATEKEY_OR_SEED
}

const WBGLBridgeSDKInstance = new WBGLBridgeSDK(config)

Using commonjs require:

const {
  ChainNames,
  WBGLBridgeSDK,
  ChaindIds
} = require('wbgl-bridge-sdk')

const { ethers } = require('ethers')
// for env secrets:
const dotenv = require('dotenv')
  const bscProvider = 'https://rpc.ankr.com/bsc'
  const provider = new ethers.providers.JsonRpcProvider(bscProvider)

  const evmPrivateKey = process.env.EVM_PRIVATE_KEY
  console.log(evmPrivateKey)
  const signer = new ethers.Wallet(evmPrivateKey, provider)
  const bnbAddress = await signer.getAddress()


  const config = {
    evmPrivateKey: evmPrivateKey, // Arbitrum, BNB chain, Ethereum privateKey etc
    provider: provider,
    chainName: ChainNames.Ethereum,
    chainId: ChaindIds.Ethereum,
    bridgeEndpoint: 'https://bglswap.com/app/',
    bglPrivateKeyOrSeed: process.env.BGL_PRIVATEKEY_OR_SEED
  }
  const wbglBridgesdkInstance = new WBGLBridgeSDK(config)
  

Swap methods

1. Swap WBGL Tokens for BGL

// address to receieve bgl from

const bglAddress = 'bgl1qh3tsz3a7l3m49xaq4xcdx8aefthchuqagmspcn' 

const wbglPair: WBGLBGLExchangePair = {
  bglAddress: bglAddress,
  wbglAmount: 5
}
const swapResult = await WBGLBridgeSDKInstance.swapWBGLforBGL(wbglPair)
console.log(swapResult)

2. Swap BGL for WBGL Tokens to BSC/Ethereum account

const blgAmountToSwap = 1 // 1BGL
const bglTxFee = 0.0001 // A minimum txFee of proposed 10,000 satoshis(0.0001BGL)

const recepientBNBAddress = '0x309C7057d20EC9EB67b21005972fF19965483Fbf'

const bGLWBGLExchangePair: BGLWBGLExchangePair = {
  recepientWBGLAddress: recepientBNBAddress,
  bglAmount: blgAmountToSwap,
  bglFee: bglTxFee
}

const swapResult = await BGLInstance.swapBGLforWBGL(bGLWBGLExchangePair)
console.log(swapResult)

On a sucessful swap:

{
  bglBridgeAddress: 'bgl1qsxt0ktqgxptn6qv6s4jhxe6rappvv6r342vmx3',
  currentWBGLBridgeBalance: '112020.082928590506503209',
  msg: 'You have successfully sent 1 to bgl1qsxt0ktqgxptn6qv6s4jhxe6rappvv6r342vmx3 to receive WBGL,  1 fee is charged. The currently available WBGL balance is 112020.082928590506503209. If you send more BGL than is available to complete the exchange, your BGL will be returned to your address.\n' +
  'Please note, that a fee of 1% will be automatically deducted from the transfer amount. This exchange pair is active for 7 days.',
  bglTxHash: '819eefaf783289c8220b5052ac2e4141b25948a18ee44d713d08db9dab634e0f',
  rpcResult: {
    result: '819eefaf783289c8220b5052ac2e4141b25948a18ee44d713d08db9dab634e0f',
    error: null,
    id: 'curltext'
  }
}

Roadmap

This library is in active development(currently in Beta!) with implemented functions as follows:

API

The following methods have been implemented and tested with coverage on Ethereum and BNBSmartChain:

  • [x] getBalanceBGL()

  • [x] getBalanceEthereum)

  • [x] getBalanceBNBChain()

  • [x] getBalanceArbitrumChain()

  • [x] getBalanceOptimismChain()

  • [x] swapBGLforBGL(bGLWBGLExchangePair: BGLWBGLExchangePair)

  • [x] swapWBGLToBGL(wBGLBGLExchangePair: BGLWBGLExchangePair)

  • [] getContracts()

  • [] getBridgeHealth()

  • [] getBridgeStatus()

Documentation

For more in-depth information on the SDK's methods, classes, and usage, refer to the official documentation.

Note: For a complete example see /examples/

Contribution Guidelines

  1. Contributions are welcome with tests to keep the coverage high We welcome contributions! Feel free to submit a feature request/file an issue etc.

License

This SDK is licensed under the MIT License. Feel free to use, modify, and distribute it according to the terms of the license.