Skip to content

Commit

Permalink
Added get balance method to fetch SOL balance of an account
Browse files Browse the repository at this point in the history
  • Loading branch information
SDargarh committed Jul 22, 2024
1 parent c511e05 commit 724badd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
- Added getAccounts() method to fetch list of generated accounts
- Added importWallet() to import account using privateKey
- Added initial test
- Added functionality to sign message
- Added functionality to sign message
- Added get balance method to fetch SOL balance of an account
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const ObservableStore = require("obs-store");
const bs58 = require("bs58");
const helper = require("./helper");
const nacl = require('tweetnacl');
const helper = require("./helper");
const ObservableStore = require("obs-store");
const solanaWeb3 = require('@solana/web3.js');


const { solana: { HD_PATH }, solana_connection: { MAINNET }} = require('./config')
Expand Down Expand Up @@ -83,5 +84,15 @@ class KeyringController {
}
}

const getBalance = async (address, network) => {
try {
const _network = helper.getNetwork(network)
const connection = new solanaWeb3.Connection(_network, "confirmed")
const accInfo = await connection.getAccountInfo(new solanaWeb3.PublicKey(address), 'confirmed')
return { balance: accInfo ? accInfo.lamports : 0 }
} catch (err) {
throw err
}
}

module.exports = { KeyringController };
module.exports = { KeyringController, getBalance };

0 comments on commit 724badd

Please sign in to comment.