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
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
Import the SDK into your TypeScript project to start using the Bitgesell WGL Bridge functionalities:
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)
// address to receieve bgl from
const bglAddress = 'bgl1qh3tsz3a7l3m49xaq4xcdx8aefthchuqagmspcn'
const wbglPair: WBGLBGLExchangePair = {
bglAddress: bglAddress,
wbglAmount: 5
}
const swapResult = await WBGLBridgeSDKInstance.swapWBGLforBGL(wbglPair)
console.log(swapResult)
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'
}
}
This library is in active development(currently in Beta!) with implemented functions as follows:
The following methods have been implemented and tested with coverage on Ethereum
and BNBSmartChain
:
-
getBalanceBGL()
-
getBalanceEthereum)
-
getBalanceBNBChain()
-
getBalanceArbitrumChain()
-
getBalanceOptimismChain()
-
swapBGLforBGL(bGLWBGLExchangePair: BGLWBGLExchangePair)
-
swapWBGLToBGL(wBGLBGLExchangePair: BGLWBGLExchangePair)
-
[]
getContracts()
-
[]
getBridgeHealth()
-
[]
getBridgeStatus()
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/
- Contributions are welcome with tests to keep the coverage high We welcome contributions! Feel free to submit a feature request/file an issue etc.
This SDK is licensed under the MIT License. Feel free to use, modify, and distribute it according to the terms of the license.