This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from naftalimurgor/fix-import-from-privatekey
Fix import from privatekey
- Loading branch information
Showing
14 changed files
with
6,152 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# EVM Privatkey | ||
EVM_PRIVATE_KEY=35a6027dca1d99f2ce38062025f1e023c5046a31495a73f3464d1fb690422e61 | ||
# EVM Seedphrase(optional) | ||
MNEMONIC= | ||
# PRIVATE_KEY or SEED phrase | ||
BGL_PRIVATEKEY_OR_SEED=govern art monster law promote you spot annual sell agree bulk that floor spawn come canyon shed moral theme basic abandon spare media glory | ||
# BGL_SEEDPHRASE=govern art monster law promote you spot annual sell agree bulk that floor spawn come canyon shed moral theme basic abandon spare media glory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.idea/* | ||
.nyc_output | ||
build | ||
node_modules | ||
test | ||
src/**.js | ||
coverage | ||
*.log | ||
yarn.lock | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const { | ||
ChainNames, | ||
WBGLBridgeSDK, | ||
ChaindIds | ||
} = require('wbgl-bridge-sdk') | ||
const { ethers } = require('ethers') | ||
const dotenv = require('dotenv') | ||
dotenv.config() | ||
|
||
const main = async () => { | ||
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) | ||
|
||
// 1. BGL -> WBGL swap | ||
|
||
const swapBGLForWBGL = async () => { | ||
const bglAmountToSwap = 1 // 1BGL | ||
const bglTxFee = 0.0001 // minimum txFee of proposed 10,000 satoshis(0.0001BGL) | ||
|
||
const BGLWBGLExchangePair = { | ||
recepientWBGLAddress: bnbAddress, | ||
bglAmount: bglAmountToSwap, | ||
bglFee: bglTxFee | ||
} | ||
try { | ||
const result = await wbglBridgesdkInstance.bgl.swapBGLforWBGL(BGLWBGLExchangePair) | ||
console.log(result) | ||
return result | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
|
||
const bglSwap = await swapBGLForWBGL() | ||
console.log(bglSwap) | ||
|
||
// WBGL -> BGL | ||
const swapWBLforBGL = async () => { | ||
const wbglPair = { | ||
bglAddress: 'bgl1qh3tsz3a7l3m49xaq4xcdx8aefthchuqagmspcn', | ||
to: bnbAddress, | ||
wbglAmount: 1 | ||
} | ||
try { | ||
const result = await wbglBridgesdkInstance.wbgl.swapWBGLforBGL(wbglPair) | ||
console.log(result) | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
} | ||
const result = await swapWBLforBGL() | ||
console.log(result) | ||
} | ||
|
||
main().catch(err => console.log(err)) |
Oops, something went wrong.