Skip to content

Commit

Permalink
Merge pull request #10 from getsafle/feature-get-balance
Browse files Browse the repository at this point in the history
Feature get balance
  • Loading branch information
apoorvq committed Feb 18, 2022
2 parents a2a9ff2 + c5d2433 commit 9550f43
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@
##### Implement import wallet functionality

- Added importWallet() to import account using privateKey.

### 1.1.0 (2022-02-16)

##### Implement get balance functionality

- Added getBalance() to fetch the balance in native currency.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
## Initialize the Eth Controller class

```
const controller = require('@getsafle/vault-eth-controller');
const { KeyringController, getBalance } = require('@getsafle/vault-eth-controller');
const ethController = new controller({
const ethController = new KeyringController({
encryptor: {
// An optional object for defining encryption schemes:
// Defaults to Browser-native SubtleCrypto.
Expand Down Expand Up @@ -64,5 +64,11 @@ const signedMsg = await ethController.signMessage(msgParams);
### Sign Typed Data (EIP-712)

```
const signedData = await ethController.signTypedMessage (msgParams);
const signedData = await ethController.signTypedMessage(msgParams);
```

### Get balance

```
const balance = await getBalance(address, web3);
```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getsafle/vault-eth-controller",
"version": "1.0.2",
"version": "1.1.0",
"description": "Ethereum controller for safle vault.",
"main": "src/index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,9 @@ class KeyringController extends EventEmitter {
}
}

module.exports = KeyringController
const getBalance = async (address, web3) => {
const balance = await web3.eth.getBalance(address);
return { balance: web3.utils.fromWei(balance, 'ether') }
}

module.exports = { KeyringController, getBalance }

0 comments on commit 9550f43

Please sign in to comment.