# Class: MoneroRpcConnection

## MoneroRpcConnection(uriOrConfigOrConnection, username, password, rejectUnauthorized)

Maintains a connection and sends requests to a Monero RPC API.

## Constructor

#### new MoneroRpcConnection(uriOrConfigOrConnection, username, password, rejectUnauthorized)

Construct a RPC connection.

Examples:

`let connection1 = new MoneroRpcConnection("http://localhost:38081", "daemon_user", "daemon_password_123")
let connection2 = new MoneroRpcConnection({
uri: http://localhost:38081,
username: "daemon_user",
password: "daemon_password_123",
rejectUnauthorized: false, // accept self-signed certificates e.g. for local development
proxyToWorker: true // proxy request to worker (default false)
});`

##### Parameters:

Name | Type | Description
--- | --- | ---
`uriOrConfigOrConnection` | string | object | MoneroRpcConnection | RPC endpoint URI, MoneroRpcConnection, or equivalent JS object ###### Properties
Name | Type | Description
--- | --- | ---
`uri` | string | URI of the RPC endpoint
`username` | string | username to authenticate with the RPC endpoint (optional)
`password` | string | password to authenticate with the RPC endpoint (optional)
`rejectUnauthorized` | boolean | rejects self-signed certificates if true (default true)
`proxyToWorker` | boolean | proxy requests to worker
`username` | string | username to authenticate with the RPC endpoint (optional)
`password` | string | password to authenticate with the RPC endpoint (optional)
`rejectUnauthorized` | boolean | reject self-signed certificates if true (default true)

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 11

### Members

#### (static) DEFAULT_CONFIG

Default RPC configuration.

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 399

### Methods

#### (async) checkConnection(timeoutInMs) → {Promise.<boolean>}

Check the connection status to update isOnline, isAuthenticated, and response time.

##### Parameters:

Name | Type | Description
--- | --- | ---
`timeoutInMs` | int | maximum response time before considered offline

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 157

##### Returns:

true if there is a change in status, false otherwise

Type
  Promise.<boolean>

#### getAttribute()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 147

#### getConfig()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 120

#### getPassword()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 103

#### getPriority()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 124

#### getProxyToWorker()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 116

#### getRejectUnauthorized()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 107

#### getResponseTime()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 213

#### getUri()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 95

#### getUsername()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 99

#### isAuthenticated() → {boolean|undefined}

Indicates if the connection is authenticated according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 209

##### Returns:

true if authenticated or no authentication, false if not authenticated, or undefined if checkConnection() has not been called

Type
  boolean | undefined

#### isConnected() → {boolean|undefined}

Indicates if the connection is connected according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 187

##### Returns:

true or false to indicate if connected, or undefined if checkConnection() has not been called

Type
  boolean | undefined

#### isOnline() → {boolean|undefined}

Indicates if the connection is online according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 198

##### Returns:

true or false to indicate if online, or undefined if checkConnection() has not been called

Type
  boolean | undefined

#### (async) sendBinaryRequest(path, params, timeoutInMs) → {Uint8Array}

Send a binary RPC request.

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | path of the binary RPC method to invoke
`params` | object | request parameters
`timeoutInMs` | int | request timeout in milliseconds

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 332

##### Returns:

the binary response

Type
  Uint8Array

#### (async) sendJsonRequest(method, params, timeoutInMs) → {object}

Send a JSON RPC request.

##### Parameters:

Name | Type | Description
--- | --- | ---
`method` | string | JSON RPC method to invoke
`params` | object | request parameters
`timeoutInMs` | int | request timeout in milliseconds

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 225

##### Returns:

is the response map

Type
  object

#### (async) sendPathRequest(path, params, timeoutInMs) → {object}

Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | JSON RPC path to invoke
`params` | object | request parameters
`timeoutInMs` | int | request timeout in milliseconds

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 283

##### Returns:

is the response map

Type
  object

#### setAttribute()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 141

#### setCredentials()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 77

#### setPriority(priority) → {MoneroRpcConnection}

Set the connection's priority relative to other connections. Priority 1 is highest, then priority 2, etc. The default priority of 0 is lowest priority.

##### Parameters:

Name | Type | Description
--- | --- | ---
`priority` | int | the connection priority (default 0)

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 135

##### Returns:

this connection

Type
  MoneroRpcConnection

#### setProxyToWorker()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 111

#### toString()

Source:
  - src/main/js/common/MoneroRpcConnection.js, line 372