@getsafle/vault-bitcoin-controller
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -12,1 +12,7 @@ ### 1.0.0 (2021-12-27) | ||
- Added importWallet() to import account using privateKey. | ||
### 1.1.0 (2022-02-16) | ||
##### Implement get balance functionality | ||
- Added getBalance() to fetch the balance in BTC. |
{ | ||
"name": "@getsafle/vault-bitcoin-controller", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -10,5 +10,5 @@ # bitcoin-controller | ||
``` | ||
const controller = require('@getsafle/vault-bitcoin-controller'); | ||
const { KeyringController, getBalance } = require('@getsafle/vault-bitcoin-controller'); | ||
const bitcoinController = new controller({ | ||
const bitcoinController = new KeyringController({ | ||
// 12 words mnemonic to create wallet | ||
@@ -61,1 +61,7 @@ mnemonic: string, | ||
``` | ||
### Get balance | ||
``` | ||
const balance = await getBalance(address, network); // if network !== TESTNET then it will fetch mainnet balance | ||
``` |
@@ -13,5 +13,4 @@ const ObservableStore = require('obs-store') | ||
class KeyringController { | ||
class BTCHdKeyring { | ||
/** | ||
@@ -150,2 +149,12 @@ * | ||
module.exports = BTCHdKeyring | ||
const getBalance = async (address, networkType) => { | ||
try { | ||
const URL = `https://sochain.com/api/v2/get_address_balance/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}/${address}` | ||
const balance = await axios.get(URL) | ||
return { balance: balance.data.data.confirmed_balance } | ||
} catch (err) { | ||
throw err | ||
} | ||
} | ||
module.exports = { KeyringController, getBalance } |
var assert = require('assert'); | ||
const bitcoinMessage = require('bitcoinjs-message') | ||
const Bitcoin = require('../src/index') | ||
const { KeyringController: Bitcoin, getBalance } = require('../src/index') | ||
const { | ||
@@ -87,5 +87,2 @@ HD_WALLET_12_MNEMONIC, | ||
console.log("signedTransaction ", signedTransaction) | ||
const sendTransaction = await bitcoinWallet.sendTransaction(signedTransaction) | ||
console.log("sendTransaction ", sendTransaction) | ||
}) | ||
@@ -104,2 +101,9 @@ | ||
it("Should get balance of the address ", async () => { | ||
const acc = await bitcoinWallet.getAccounts() | ||
const balance = await getBalance(acc[0], opts.network) | ||
console.log("acc ", acc) | ||
console.log("balance ", balance) | ||
}) | ||
}) |
21689
392
66