-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...network-interoperability/bridge-contracts/binance-smart-chain/BinanceSmartChainBridge.sol
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,31 @@ | ||
const Web3 = require("web3"); | ||
const binanceSmartChainBridgeContract = require("./BinanceSmartChainBridge.sol"); | ||
|
||
class BinanceSmartChainBridge { | ||
constructor(binanceSmartChainAddress, piNetworkAddress) { | ||
this.binanceSmartChainAddress = binanceSmartChainAddress; | ||
this.piNetworkAddress = piNetworkAddress; | ||
this.web3 = new Web3(new Web3.providers.HttpProvider("https://bsc-dataseed.binance.org/api/v1/bc/BSC/main")); | ||
} | ||
|
||
async transferTokens(token, amount) { | ||
const txCount = await this.web3.eth.getTransactionCount(this.binanceSmartChainAddress); | ||
const tx = { | ||
from: this.binanceSmartChainAddress, | ||
to: this.piNetworkAddress, | ||
value: amount, | ||
gas: "20000", | ||
gasPrice: "20.0", | ||
nonce: txCount | ||
}; | ||
const signedTx = await this.web3.eth.accounts.signTransaction(tx, "YOUR_PRIVATE_KEY"); | ||
await this.web3.eth.sendSignedTransaction(signedTx.rawTransaction); | ||
} | ||
|
||
async getBalance(token) { | ||
const balance = await this.web3.eth.getBalance(this.binanceSmartChainAddress); | ||
return balance; | ||
} | ||
} | ||
|
||
module.exports = BinanceSmartChainBridge; |