diff --git a/docs/bank.md b/docs/bank.md index 35be667..afe5192 100644 --- a/docs/bank.md +++ b/docs/bank.md @@ -507,3 +507,12 @@ console.log(res); ``` > If you don't understand upgradeRequest and upgradeNotice, check out the [documentation](https://thenewboston.com/guide/resync-process) at thenewboston.com + +## Getting the Bank's Primary Validator + +Simply use the `Bank.getBankPV` method which returns the formatted url of the Primary Validator + +```ts +const bank = new tnb.Bank("http://143.110.137.54"); +const pv = await bank.getBankPV(); +``` diff --git a/docs/index.md b/docs/index.md index 571a01a..055c684 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,9 +5,10 @@ Here, you will learn about how to use all of what thenewboston-js has to offer. ## Getting Started There are two ways to use the library. - - Clone the repository / download the files and load them into your project. - - Using NPM ``npm install thenewboston ``, this will install the library to your package.json file - + +- Clone the repository / download the files and load them into your project. +- Using NPM `npm install thenewboston `, this will install the library to your package.json file + > For simplicity, we will not be including `import` or `require` statements in our examples. ## Table of Contents @@ -46,6 +47,8 @@ There are two ways to use the library. - [Sending Upgrade Notice and Upgrade Request](bank.md#sending-upgrade-notice-and-upgrade-request) + - [Getting the Bank's Primary Validator](bank.md#getting-the-bank's-primary-validator) + - [Validator](validator.md#validator) - [Creating Validators](validator.md#creating-banks) diff --git a/src/bank.ts b/src/bank.ts index 2c4568f..0d3f92d 100644 --- a/src/bank.ts +++ b/src/bank.ts @@ -1,4 +1,5 @@ import { ServerNode } from "./server-node"; +import { PrimaryValidator } from "./primary-validator"; import type { PaginationOptions, BankConfigResponse, @@ -141,4 +142,14 @@ export class Bank extends ServerNode { async getValidators(options: Partial = {}) { return await super.getPaginatedData("/validators", options); } + + /** + * Gets the PrimaryValidator for the current bank. + */ + async getBankPV() { + const { primary_validator } = await this.getConfig(); + return new PrimaryValidator( + `${primary_validator.protocol}://${primary_validator.ip_address}:${primary_validator.port}` + ); + } }