Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from naftalimurgor/fix-import-from-privatekey
Browse files Browse the repository at this point in the history
Fix import from privatekey
  • Loading branch information
naftalimurgor authored Jul 1, 2024
2 parents 05ac815 + 66c06db commit 3813c97
Show file tree
Hide file tree
Showing 14 changed files with 6,152 additions and 56 deletions.
56 changes: 47 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,57 @@ import {
WBGLBGLExchangePair,
} from 'wbgl-bridge-sdk'

const provider = new ethers.providers.JsonRpcProvider(bscNodeRPC)
const bscNodeRPC = 'https://rpc.ankr.com/bsc'
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: process.env.EVM_PRIVATEKEY as string,
provider: provider,
chainName: ChainNames.Ethereum,
chainId: ChaindIds.Ethereum,
bridgeEndpoint: 'https://bglswap.com/app/',
bglPrivateKey: process.env.BGL_PRIVATEKEY as string
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`:
```javascript
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`
```typescript
Expand All @@ -73,7 +109,7 @@ const wbglPair: WBGLBGLExchangePair = {
bglAddress: bglAddress,
wbglAmount: 5
}
const swapResult = await WBGLBridgeSDKInstance.swapWBGLtoBGL(wbglPair)
const swapResult = await WBGLBridgeSDKInstance.swapWBGLforBGL(wbglPair)
console.log(swapResult)
```

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

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/).

Note: For a complete example see `/examples/`

## Contribution Guidelines

1. Contributions are welcome with tests to keep the coverage high
Expand Down
7 changes: 7 additions & 0 deletions examples/.env.example
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
10 changes: 10 additions & 0 deletions examples/.gitignore
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
71 changes: 71 additions & 0 deletions examples/index.js
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))
Loading

0 comments on commit 3813c97

Please sign in to comment.