Skip to content

Commit 3813c97

Browse files
Merge pull request #15 from naftalimurgor/fix-import-from-privatekey
Fix import from privatekey
2 parents 05ac815 + 66c06db commit 3813c97

14 files changed

+6152
-56
lines changed

README.md

+47-9
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,57 @@ import {
4747
WBGLBGLExchangePair,
4848
} from 'wbgl-bridge-sdk'
4949

50-
const provider = new ethers.providers.JsonRpcProvider(bscNodeRPC)
51-
const bscNodeRPC = 'https://rpc.ankr.com/bsc'
50+
const bscProvider = 'https://rpc.ankr.com/bsc'
51+
const provider = new ethers.providers.JsonRpcProvider(bscProvider)
52+
const evmPrivateKey = process.env.EVM_PRIVATE_KEY
53+
const signer = new ethers.Wallet(evmPrivateKey, provider)
54+
const bnbAddress = await signer.getAddress()
55+
5256

5357
const config: IBridgeConfig = {
54-
evmPrivateKey: process.env.EVM_PRIVATEKEY as string,
55-
provider: provider,
56-
chainName: ChainNames.Ethereum,
57-
chainId: ChaindIds.Ethereum,
58-
bridgeEndpoint: 'https://bglswap.com/app/',
59-
bglPrivateKey: process.env.BGL_PRIVATEKEY as string
58+
evmPrivateKey: evmPrivateKey, // Arbitrum, BNB chain, Ethereum privateKey etc
59+
provider: provider,
60+
chainName: ChainNames.Ethereum,
61+
chainId: ChaindIds.Ethereum,
62+
bridgeEndpoint: 'https://bglswap.com/app/',
63+
bglPrivateKeyOrSeed: process.env.BGL_PRIVATEKEY_OR_SEED
6064
}
6165

6266
const WBGLBridgeSDKInstance = new WBGLBridgeSDK(config)
6367

6468
```
69+
Using `commonjs` `require`:
70+
```javascript
71+
const {
72+
ChainNames,
73+
WBGLBridgeSDK,
74+
ChaindIds
75+
} = require('wbgl-bridge-sdk')
76+
77+
const { ethers } = require('ethers')
78+
// for env secrets:
79+
const dotenv = require('dotenv')
80+
const bscProvider = 'https://rpc.ankr.com/bsc'
81+
const provider = new ethers.providers.JsonRpcProvider(bscProvider)
82+
83+
const evmPrivateKey = process.env.EVM_PRIVATE_KEY
84+
console.log(evmPrivateKey)
85+
const signer = new ethers.Wallet(evmPrivateKey, provider)
86+
const bnbAddress = await signer.getAddress()
87+
88+
89+
const config = {
90+
evmPrivateKey: evmPrivateKey, // Arbitrum, BNB chain, Ethereum privateKey etc
91+
provider: provider,
92+
chainName: ChainNames.Ethereum,
93+
chainId: ChaindIds.Ethereum,
94+
bridgeEndpoint: 'https://bglswap.com/app/',
95+
bglPrivateKeyOrSeed: process.env.BGL_PRIVATEKEY_OR_SEED
96+
}
97+
const wbglBridgesdkInstance = new WBGLBridgeSDK(config)
98+
99+
```
100+
## Swap methods
65101

66102
### 1. Swap `WBGL` Tokens for `BGL`
67103
```typescript
@@ -73,7 +109,7 @@ const wbglPair: WBGLBGLExchangePair = {
73109
bglAddress: bglAddress,
74110
wbglAmount: 5
75111
}
76-
const swapResult = await WBGLBridgeSDKInstance.swapWBGLtoBGL(wbglPair)
112+
const swapResult = await WBGLBridgeSDKInstance.swapWBGLforBGL(wbglPair)
77113
console.log(swapResult)
78114
```
79115

@@ -135,6 +171,8 @@ The following methods have been implemented and tested with coverage on `Ethereu
135171

136172
For more in-depth information on the SDK's methods, classes, and usage, refer to the [official documentation](https://naftalimurgor.github.io/wbgl-brigde-sdk/).
137173

174+
Note: For a complete example see `/examples/`
175+
138176
## Contribution Guidelines
139177

140178
1. Contributions are welcome with tests to keep the coverage high

examples/.env.example

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# EVM Privatkey
2+
EVM_PRIVATE_KEY=35a6027dca1d99f2ce38062025f1e023c5046a31495a73f3464d1fb690422e61
3+
# EVM Seedphrase(optional)
4+
MNEMONIC=
5+
# PRIVATE_KEY or SEED phrase
6+
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
7+
# 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

examples/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.idea/*
2+
.nyc_output
3+
build
4+
node_modules
5+
test
6+
src/**.js
7+
coverage
8+
*.log
9+
yarn.lock
10+
.env

examples/index.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const {
2+
ChainNames,
3+
WBGLBridgeSDK,
4+
ChaindIds
5+
} = require('wbgl-bridge-sdk')
6+
const { ethers } = require('ethers')
7+
const dotenv = require('dotenv')
8+
dotenv.config()
9+
10+
const main = async () => {
11+
const bscProvider = 'https://rpc.ankr.com/bsc'
12+
const provider = new ethers.providers.JsonRpcProvider(bscProvider)
13+
14+
const evmPrivateKey = process.env.EVM_PRIVATE_KEY
15+
console.log(evmPrivateKey)
16+
const signer = new ethers.Wallet(evmPrivateKey, provider)
17+
const bnbAddress = await signer.getAddress()
18+
19+
20+
const config = {
21+
evmPrivateKey: evmPrivateKey, // Arbitrum, BNB chain, Ethereum privateKey etc
22+
provider: provider,
23+
chainName: ChainNames.Ethereum,
24+
chainId: ChaindIds.Ethereum,
25+
bridgeEndpoint: 'https://bglswap.com/app/',
26+
bglPrivateKeyOrSeed: process.env.BGL_PRIVATEKEY_OR_SEED
27+
}
28+
const wbglBridgesdkInstance = new WBGLBridgeSDK(config)
29+
30+
// 1. BGL -> WBGL swap
31+
32+
const swapBGLForWBGL = async () => {
33+
const bglAmountToSwap = 1 // 1BGL
34+
const bglTxFee = 0.0001 // minimum txFee of proposed 10,000 satoshis(0.0001BGL)
35+
36+
const BGLWBGLExchangePair = {
37+
recepientWBGLAddress: bnbAddress,
38+
bglAmount: bglAmountToSwap,
39+
bglFee: bglTxFee
40+
}
41+
try {
42+
const result = await wbglBridgesdkInstance.bgl.swapBGLforWBGL(BGLWBGLExchangePair)
43+
console.log(result)
44+
return result
45+
} catch (error) {
46+
console.error(error)
47+
}
48+
}
49+
50+
const bglSwap = await swapBGLForWBGL()
51+
console.log(bglSwap)
52+
53+
// WBGL -> BGL
54+
const swapWBLforBGL = async () => {
55+
const wbglPair = {
56+
bglAddress: 'bgl1qh3tsz3a7l3m49xaq4xcdx8aefthchuqagmspcn',
57+
to: bnbAddress,
58+
wbglAmount: 1
59+
}
60+
try {
61+
const result = await wbglBridgesdkInstance.wbgl.swapWBGLforBGL(wbglPair)
62+
console.log(result)
63+
} catch (error) {
64+
console.log(error)
65+
}
66+
}
67+
const result = await swapWBLforBGL()
68+
console.log(result)
69+
}
70+
71+
main().catch(err => console.log(err))

0 commit comments

Comments
 (0)