# Context

Context in which the SDK is being used

* Holds the current low level API
* Holds the current keyring pair
* Holds the current Identity

## Hierarchy

* **Context**

## Index

### Properties

* [currentPair](/polymesh-sdk-api-reference/docs-v2/classes/context.md#optional-currentpair)
* [isArchiveNode](/polymesh-sdk-api-reference/docs-v2/classes/context.md#isarchivenode)
* [polymeshApi](/polymesh-sdk-api-reference/docs-v2/classes/context.md#polymeshapi)

### Accessors

* [middlewareApi](/polymesh-sdk-api-reference/docs-v2/classes/context.md#middlewareapi)

### Methods

* [accountBalance](/polymesh-sdk-api-reference/docs-v2/classes/context.md#accountbalance)
* [getAccounts](/polymesh-sdk-api-reference/docs-v2/classes/context.md#getaccounts)
* [getCurrentAccount](/polymesh-sdk-api-reference/docs-v2/classes/context.md#getcurrentaccount)
* [getCurrentIdentity](/polymesh-sdk-api-reference/docs-v2/classes/context.md#getcurrentidentity)
* [getCurrentPair](/polymesh-sdk-api-reference/docs-v2/classes/context.md#getcurrentpair)
* [getInvalidDids](/polymesh-sdk-api-reference/docs-v2/classes/context.md#getinvaliddids)
* [getLatestBlock](/polymesh-sdk-api-reference/docs-v2/classes/context.md#getlatestblock)
* [getSecondaryKeys](/polymesh-sdk-api-reference/docs-v2/classes/context.md#getsecondarykeys)
* [getTransactionArguments](/polymesh-sdk-api-reference/docs-v2/classes/context.md#gettransactionarguments)
* [getTransactionFees](/polymesh-sdk-api-reference/docs-v2/classes/context.md#gettransactionfees)
* [isMiddlewareAvailable](/polymesh-sdk-api-reference/docs-v2/classes/context.md#ismiddlewareavailable)
* [isMiddlewareEnabled](/polymesh-sdk-api-reference/docs-v2/classes/context.md#ismiddlewareenabled)
* [issuedClaims](/polymesh-sdk-api-reference/docs-v2/classes/context.md#issuedclaims)
* [queryMiddleware](/polymesh-sdk-api-reference/docs-v2/classes/context.md#querymiddleware)
* [setPair](/polymesh-sdk-api-reference/docs-v2/classes/context.md#setpair)
* [create](/polymesh-sdk-api-reference/docs-v2/classes/context.md#static-create)

## Properties

### `Optional` currentPair

• **currentPair**? : [*KeyringPair*](/polymesh-sdk-api-reference/docs-v2/interfaces/keyringpair.md)

*Defined in* [*src/base/Context.ts:76*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L76)

### isArchiveNode

• **isArchiveNode**: *boolean* = false

*Defined in* [*src/base/Context.ts:81*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L81)

Whether the current node is an archive node (contains a full history from genesis onward) or not

### polymeshApi

• **polymeshApi**: *ApiPromise*

*Defined in* [*src/base/Context.ts:74*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L74)

## Accessors

### middlewareApi

• **get middlewareApi**(): *ApolloClient‹NormalizedCacheObject›*

*Defined in* [*src/base/Context.ts:657*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L657)

Retrieve the middleware client

**`throws`** if cred entials are not set

**Returns:** *ApolloClient‹NormalizedCacheObject›*

## Methods

### accountBalance

▸ **accountBalance**(`account?`: string | [Account](/polymesh-sdk-api-reference/docs-v2/classes/account.md)): *Promise‹*[*AccountBalance*](/polymesh-sdk-api-reference/docs-v2/interfaces/accountbalance.md)*›*

*Defined in* [*src/base/Context.ts:233*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L233)

Retrieve the account level POLYX balance

**`note`** can be subscribed to

**Parameters:**

| Name       | Type                                                                        |
| ---------- | --------------------------------------------------------------------------- |
| `account?` | string \| [Account](/polymesh-sdk-api-reference/docs-v2/classes/account.md) |

**Returns:** *Promise‹*[*AccountBalance*](/polymesh-sdk-api-reference/docs-v2/interfaces/accountbalance.md)*›*

▸ **accountBalance**(`account`: string | [Account](/polymesh-sdk-api-reference/docs-v2/classes/account.md) | undefined, `callback`: [SubCallback](/polymesh-sdk-api-reference/docs-v2/globals.md#subcallback)‹[AccountBalance](/polymesh-sdk-api-reference/docs-v2/interfaces/accountbalance.md)›): *Promise‹*[*UnsubCallback*](/polymesh-sdk-api-reference/docs-v2/globals.md#unsubcallback)*›*

*Defined in* [*src/base/Context.ts:234*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L234)

Retrieve the account level POLYX balance

**`note`** can be subscribed to

**Parameters:**

| Name       | Type                                                                                                                                                          |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `account`  | string \| [Account](/polymesh-sdk-api-reference/docs-v2/classes/account.md) \| undefined                                                                      |
| `callback` | [SubCallback](/polymesh-sdk-api-reference/docs-v2/globals.md#subcallback)‹[AccountBalance](/polymesh-sdk-api-reference/docs-v2/interfaces/accountbalance.md)› |

**Returns:** *Promise‹*[*UnsubCallback*](/polymesh-sdk-api-reference/docs-v2/globals.md#unsubcallback)*›*

### getAccounts

▸ **getAccounts**(): *Array‹*[*AccountData*](/polymesh-sdk-api-reference/docs-v2/interfaces/accountdata.md)*›*

*Defined in* [*src/base/Context.ts:206*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L206)

Retrieve a list of addresses associated with the account

**Returns:** *Array‹*[*AccountData*](/polymesh-sdk-api-reference/docs-v2/interfaces/accountdata.md)*›*

### getCurrentAccount

▸ **getCurrentAccount**(): [*CurrentAccount*](/polymesh-sdk-api-reference/docs-v2/classes/currentaccount.md)

*Defined in* [*src/base/Context.ts:292*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L292)

Retrieve current Account

**`throws`** if there is no current account associated to the SDK instance

**Returns:** [*CurrentAccount*](/polymesh-sdk-api-reference/docs-v2/classes/currentaccount.md)

### getCurrentIdentity

▸ **getCurrentIdentity**(): *Promise‹*[*CurrentIdentity*](/polymesh-sdk-api-reference/docs-v2/classes/currentidentity.md)*›*

*Defined in* [*src/base/Context.ts:312*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L312)

Retrieve current Identity

**`throws`** if there is no Identity associated to the current Account (or there is no current Account associated to the SDK instance)

**Returns:** *Promise‹*[*CurrentIdentity*](/polymesh-sdk-api-reference/docs-v2/classes/currentidentity.md)*›*

### getCurrentPair

▸ **getCurrentPair**(): [*KeyringPair*](/polymesh-sdk-api-reference/docs-v2/interfaces/keyringpair.md)

*Defined in* [*src/base/Context.ts:332*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L332)

Retrieve current Keyring Pair

**`throws`** if there is no Account associated to the SDK instance

**Returns:** [*KeyringPair*](/polymesh-sdk-api-reference/docs-v2/interfaces/keyringpair.md)

### getInvalidDids

▸ **getInvalidDids**(`identities`: (string | [Identity](/polymesh-sdk-api-reference/docs-v2/classes/identity.md)‹›)\[]): *Promise‹string\[]›*

*Defined in* [*src/base/Context.ts:347*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L347)

Check whether Identities exist

**Parameters:**

| Name         | Type                                                                                 |
| ------------ | ------------------------------------------------------------------------------------ |
| `identities` | (string \| [Identity](/polymesh-sdk-api-reference/docs-v2/classes/identity.md)‹›)\[] |

**Returns:** *Promise‹string\[]›*

### getLatestBlock

▸ **getLatestBlock**(): *Promise‹BigNumber›*

*Defined in* [*src/base/Context.ts:715*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L715)

Retrieve the latest block number

**Returns:** *Promise‹BigNumber›*

### getSecondaryKeys

▸ **getSecondaryKeys**(): *Promise‹*[*SecondaryKey*](/polymesh-sdk-api-reference/docs-v2/interfaces/secondarykey.md)*\[]›*

*Defined in* [*src/base/Context.ts:545*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L545)

Retrieve the list of secondary keys related to the Account

**`note`** can be subscribed to

**Returns:** *Promise‹*[*SecondaryKey*](/polymesh-sdk-api-reference/docs-v2/interfaces/secondarykey.md)*\[]›*

▸ **getSecondaryKeys**(`callback`: [SubCallback](/polymesh-sdk-api-reference/docs-v2/globals.md#subcallback)‹[SecondaryKey](/polymesh-sdk-api-reference/docs-v2/interfaces/secondarykey.md)\[]›): *Promise‹*[*UnsubCallback*](/polymesh-sdk-api-reference/docs-v2/globals.md#unsubcallback)*›*

*Defined in* [*src/base/Context.ts:546*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L546)

**Parameters:**

| Name       | Type                                                                                                                                                         |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `callback` | [SubCallback](/polymesh-sdk-api-reference/docs-v2/globals.md#subcallback)‹[SecondaryKey](/polymesh-sdk-api-reference/docs-v2/interfaces/secondarykey.md)\[]› |

**Returns:** *Promise‹*[*UnsubCallback*](/polymesh-sdk-api-reference/docs-v2/globals.md#unsubcallback)*›*

### getTransactionArguments

▸ **getTransactionArguments**(`args`: object): [*TransactionArgument*](/polymesh-sdk-api-reference/docs-v2/globals.md#transactionargument)*\[]*

*Defined in* [*src/base/Context.ts:397*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L397)

Retrieve the types of arguments that a certain transaction requires to be run

**Parameters:**

▪ **args**: *object*

| Name  | Type  | Description                                                                      |
| ----- | ----- | -------------------------------------------------------------------------------- |
| `tag` | TxTag | tag associated with the transaction that will be executed if the proposal passes |

**Returns:** [*TransactionArgument*](/polymesh-sdk-api-reference/docs-v2/globals.md#transactionargument)*\[]*

### getTransactionFees

▸ **getTransactionFees**(`tag`: TxTag): *Promise‹BigNumber›*

*Defined in* [*src/base/Context.ts:370*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L370)

Retrieve the protocol fees associated with running a specific transaction

**Parameters:**

| Name  | Type  | Description                                                            |
| ----- | ----- | ---------------------------------------------------------------------- |
| `tag` | TxTag | transaction tag (i.e. TxTags.asset.CreateAsset or "asset.createAsset") |

**Returns:** *Promise‹BigNumber›*

### isMiddlewareAvailable

▸ **isMiddlewareAvailable**(): *Promise‹boolean›*

*Defined in* [*src/base/Context.ts:702*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L702)

Return whether the middleware is enabled and online

**Returns:** *Promise‹boolean›*

### isMiddlewareEnabled

▸ **isMiddlewareEnabled**(): *boolean*

*Defined in* [*src/base/Context.ts:695*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L695)

Return whether the middleware was enabled at startup

**Returns:** *boolean*

### issuedClaims

▸ **issuedClaims**(`opts`: object): *Promise‹*[*ResultSet*](/polymesh-sdk-api-reference/docs-v2/interfaces/resultset.md)*‹*[*ClaimData*](/polymesh-sdk-api-reference/docs-v2/interfaces/claimdata.md)*››*

*Defined in* [*src/base/Context.ts:587*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L587)

Retrieve a list of claims. Can be filtered using parameters

**`note`** uses the middleware

**Parameters:**

▪`Default value` **opts**: *object*= {}

| Name                   | Type                                                                                 | Description                                                                               |
| ---------------------- | ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| `claimTypes?`          | [ClaimType](/polymesh-sdk-api-reference/docs-v2/enums/claimtype.md)\[]               | types of the claims to fetch. Defaults to any type                                        |
| `includeExpired?`      | undefined \| false \| true                                                           | whether to include expired claims. Defaults to true                                       |
| `size?`                | undefined \| number                                                                  | page size                                                                                 |
| `start?`               | undefined \| number                                                                  | page offset                                                                               |
| `targets?`             | (string \| [Identity](/polymesh-sdk-api-reference/docs-v2/classes/identity.md)‹›)\[] | identities (or Identity IDs) for which to fetch claims (targets). Defaults to all targets |
| `trustedClaimIssuers?` | (string \| [Identity](/polymesh-sdk-api-reference/docs-v2/classes/identity.md)‹›)\[] | identity IDs of claim issuers. Defaults to all claim issuers                              |

**Returns:** *Promise‹*[*ResultSet*](/polymesh-sdk-api-reference/docs-v2/interfaces/resultset.md)*‹*[*ClaimData*](/polymesh-sdk-api-reference/docs-v2/interfaces/claimdata.md)*››*

### queryMiddleware

▸ **queryMiddleware**‹**Result**›(`query`: GraphqlQuery‹unknown›): *Promise‹ApolloQueryResult‹Result››*

*Defined in* [*src/base/Context.ts:673*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L673)

Make a query to the middleware server using the apollo client

**Type parameters:**

▪ **Result**: *Partial‹Query›*

**Parameters:**

| Name    | Type                  |
| ------- | --------------------- |
| `query` | GraphqlQuery‹unknown› |

**Returns:** *Promise‹ApolloQueryResult‹Result››*

### setPair

▸ **setPair**(`address`: string): *Promise‹void›*

*Defined in* [*src/base/Context.ts:216*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L216)

Set a pair as the current account keyring pair

**Parameters:**

| Name      | Type   |
| --------- | ------ |
| `address` | string |

**Returns:** *Promise‹void›*

### `Static` create

▸ **create**(`params`: object): *Promise‹*[*Context*](/polymesh-sdk-api-reference/docs-v2/classes/context.md)*›*

*Defined in* [*src/base/Context.ts:112*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L112)

Create the Context instance

**Parameters:**

▪ **params**: *object*

| Name            | Type                                        |
| --------------- | ------------------------------------------- |
| `middlewareApi` | ApolloClient‹NormalizedCacheObject› \| null |
| `polymeshApi`   | ApiPromise                                  |
| `seed`          | string                                      |

**Returns:** *Promise‹*[*Context*](/polymesh-sdk-api-reference/docs-v2/classes/context.md)*›*

▸ **create**(`params`: object): *Promise‹*[*Context*](/polymesh-sdk-api-reference/docs-v2/classes/context.md)*›*

*Defined in* [*src/base/Context.ts:118*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L118)

Create the Context instance

**Parameters:**

▪ **params**: *object*

| Name            | Type                                                                          |
| --------------- | ----------------------------------------------------------------------------- |
| `keyring`       | [CommonKeyring](/polymesh-sdk-api-reference/docs-v2/globals.md#commonkeyring) |
| `middlewareApi` | ApolloClient‹NormalizedCacheObject› \| null                                   |
| `polymeshApi`   | ApiPromise                                                                    |

**Returns:** *Promise‹*[*Context*](/polymesh-sdk-api-reference/docs-v2/classes/context.md)*›*

▸ **create**(`params`: object): *Promise‹*[*Context*](/polymesh-sdk-api-reference/docs-v2/classes/context.md)*›*

*Defined in* [*src/base/Context.ts:124*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L124)

Create the Context instance

**Parameters:**

▪ **params**: *object*

| Name            | Type                                        |
| --------------- | ------------------------------------------- |
| `middlewareApi` | ApolloClient‹NormalizedCacheObject› \| null |
| `polymeshApi`   | ApiPromise                                  |
| `uri`           | string                                      |

**Returns:** *Promise‹*[*Context*](/polymesh-sdk-api-reference/docs-v2/classes/context.md)*›*

▸ **create**(`params`: object): *Promise‹*[*Context*](/polymesh-sdk-api-reference/docs-v2/classes/context.md)*›*

*Defined in* [*src/base/Context.ts:130*](https://github.com/PolymathNetwork/polymesh-sdk/blob/5b409784/src/base/Context.ts#L130)

Create the Context instance

**Parameters:**

▪ **params**: *object*

| Name            | Type                                        |
| --------------- | ------------------------------------------- |
| `middlewareApi` | ApolloClient‹NormalizedCacheObject› \| null |
| `polymeshApi`   | ApiPromise                                  |

**Returns:** *Promise‹*[*Context*](/polymesh-sdk-api-reference/docs-v2/classes/context.md)*›*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.polymath.network/polymesh-sdk-api-reference/docs-v2/classes/context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
