Skip to main content

avalanchecore.avalanchecore-1

avalancheAvalancheCoreAvalancheCore

Class: AvalancheCore

AvalancheCore is middleware for interacting with Avalanche node RPC APIs.

Example usage:

let avalanche = new AvalancheCore("127.0.0.1", 9650, "https")

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

+ new AvalancheCore(host: string, port: number, protocol: string): AvalancheCore

Defined in src/avalanche.ts:439

Creates a new Avalanche instance. Sets the address and port of the main Avalanche Client.

Parameters:

NameTypeDefaultDescription
hoststring-The hostname to resolve to reach the Avalanche Client APIs
portnumber-The port to resolve to reach the Avalanche Client APIs
protocolstring"http"The protocol string to use before a "://" in a request, ex: "http", "https", "git", "ws", etc ...

Returns: AvalancheCore

Properties

Protected apis

apis: object

Defined in src/avalanche.ts:36

Type declaration:


Protected auth

auth: string = undefined

Defined in src/avalanche.ts:33


Protected headers

headers: object

Defined in src/avalanche.ts:34

Type declaration:

  • [ k: string]: string

Protected host

host: string

Defined in src/avalanche.ts:30


Protected hrp

hrp: string = ""

Defined in src/avalanche.ts:27


Protected ip

ip: string

Defined in src/avalanche.ts:29


Protected networkID

networkID: number = 0

Defined in src/avalanche.ts:26


Protected port

port: number

Defined in src/avalanche.ts:31


Protected protocol

protocol: string

Defined in src/avalanche.ts:28


Protected requestConfig

requestConfig: AxiosRequestConfig

Defined in src/avalanche.ts:35


Protected url

url: string

Defined in src/avalanche.ts:32

Methods

Protected _setHeaders

_setHeaders(headers: any): AxiosRequestHeaders

Defined in src/avalanche.ts:206

Parameters:

NameType
headersany

Returns: AxiosRequestHeaders


addAPI

addAPIGA›(apiName: string, ConstructorFN: object, baseurl: string, ...args: any[]): void

Defined in src/avalanche.ts:238

Adds an API to the middleware. The API resolves to a registered blockchain's RPC.

In TypeScript:

avalanche.addAPI<MyVMClass>("mychain", MyVMClass, "/ext/bc/mychain")

In Javascript:

avalanche.addAPI("mychain", MyVMClass, "/ext/bc/mychain")

Type parameters:

GA: APIBase

Class of the API being added

Parameters:

NameTypeDefaultDescription
apiNamestring-A label for referencing the API in the future
ConstructorFNobject-A reference to the class which instantiates the API
baseurlstringundefinedPath to resolve to reach the API
...argsany[]--

Returns: void


api

apiGA›(apiName: string): GA

Defined in src/avalanche.ts:260

Retrieves a reference to an API by its apiName label.

Type parameters:

GA: APIBase

Parameters:

NameTypeDescription
apiNamestringName of the API to return

Returns: GA


delete

delete(baseurl: string, getdata: object, headers: object, axiosConfig: AxiosRequestConfig): Promise‹RequestResponseData

Defined in src/avalanche.ts:341

Makes a DELETE call to an API.

Parameters:

NameTypeDefaultDescription
baseurlstring-Path to the API
getdataobject-Object containing the key value pairs sent in DELETE
headersobject{}An array HTTP Request Headers
axiosConfigAxiosRequestConfigundefinedConfiguration for the axios javascript library that will be the foundation for the rest of the parameters

Returns: Promise‹RequestResponseData

A promise for RequestResponseData


get

get(baseurl: string, getdata: object, headers: object, axiosConfig: AxiosRequestConfig): Promise‹RequestResponseData

Defined in src/avalanche.ts:315

Makes a GET call to an API.

Parameters:

NameTypeDefaultDescription
baseurlstring-Path to the api
getdataobject-Object containing the key value pairs sent in GET
headersobject{}An array HTTP Request Headers
axiosConfigAxiosRequestConfigundefinedConfiguration for the axios javascript library that will be the foundation for the rest of the parameters

Returns: Promise‹RequestResponseData

A promise for RequestResponseData


getHRP

getHRP(): string

Defined in src/avalanche.ts:126

Returns the Human-Readable-Part of the network associated with this key.

Returns: string

The KeyPair's Human-Readable-Part of the network's Bech32 addressing scheme


getHeaders

getHeaders(): object

Defined in src/avalanche.ts:101

Returns the custom headers

Returns: object


getHost

getHost(): string

Defined in src/avalanche.ts:81

Returns the host for the Avalanche node.

Returns: string


getIP

getIP(): string

Defined in src/avalanche.ts:86

Returns the IP for the Avalanche node.

Returns: string


getNetworkID

getNetworkID(): number

Defined in src/avalanche.ts:111

Returns the networkID

Returns: number


getPort

getPort(): number

Defined in src/avalanche.ts:91

Returns the port for the Avalanche node.

Returns: number


getProtocol

getProtocol(): string

Defined in src/avalanche.ts:76

Returns the protocol such as "http", "https", "git", "ws", etc.

Returns: string


getRequestConfig

getRequestConfig(): AxiosRequestConfig

Defined in src/avalanche.ts:106

Returns the custom request config

Returns: AxiosRequestConfig


getURL

getURL(): string

Defined in src/avalanche.ts:96

Returns the URL of the Avalanche node (ip + port)

Returns: string


patch

patch(baseurl: string, getdata: object, postdata: string | object | ArrayBuffer | ArrayBufferView, headers: object, axiosConfig: AxiosRequestConfig): Promise‹RequestResponseData

Defined in src/avalanche.ts:425

Makes a PATCH call to an API.

Parameters:

NameTypeDefaultDescription
baseurlstring-Path to the baseurl
getdataobject-Object containing the key value pairs sent in PATCH
postdatastring | object | ArrayBuffer | ArrayBufferView-Object containing the key value pairs sent in PATCH
headersobject{}An array HTTP Request Headers
axiosConfigAxiosRequestConfigundefinedConfiguration for the axios javascript library that will be the foundation for the rest of the parameters

Returns: Promise‹RequestResponseData

A promise for RequestResponseData


post

post(baseurl: string, getdata: object, postdata: string | object | ArrayBuffer | ArrayBufferView, headers: object, axiosConfig: AxiosRequestConfig): Promise‹RequestResponseData

Defined in src/avalanche.ts:368

Makes a POST call to an API.

Parameters:

NameTypeDefaultDescription
baseurlstring-Path to the API
getdataobject-Object containing the key value pairs sent in POST
postdatastring | object | ArrayBuffer | ArrayBufferView-Object containing the key value pairs sent in POST
headersobject{}An array HTTP Request Headers
axiosConfigAxiosRequestConfigundefinedConfiguration for the axios javascript library that will be the foundation for the rest of the parameters

Returns: Promise‹RequestResponseData

A promise for RequestResponseData


put

put(baseurl: string, getdata: object, postdata: string | object | ArrayBuffer | ArrayBufferView, headers: object, axiosConfig: AxiosRequestConfig): Promise‹RequestResponseData

Defined in src/avalanche.ts:396

Makes a PUT call to an API.

Parameters:

NameTypeDefaultDescription
baseurlstring-Path to the baseurl
getdataobject-Object containing the key value pairs sent in PUT
postdatastring | object | ArrayBuffer | ArrayBufferView-Object containing the key value pairs sent in PUT
headersobject{}An array HTTP Request Headers
axiosConfigAxiosRequestConfigundefinedConfiguration for the axios javascript library that will be the foundation for the rest of the parameters

Returns: Promise‹RequestResponseData

A promise for RequestResponseData


removeAllHeaders

removeAllHeaders(): void

Defined in src/avalanche.ts:159

Removes all headers.

Returns: void


removeAllRequestConfigs

removeAllRequestConfigs(): void

Defined in src/avalanche.ts:189

Removes all request configs.

Returns: void


removeHeader

removeHeader(key: string): void

Defined in src/avalanche.ts:152

Removes a previously added custom header.

Parameters:

NameTypeDescription
keystringHeader name

Returns: void


removeRequestConfig

removeRequestConfig(key: string): void

Defined in src/avalanche.ts:182

Removes a previously added request config.

Parameters:

NameTypeDescription
keystringHeader name

Returns: void


setAddress

setAddress(host: string, port: number, protocol: string): void

Defined in src/avalanche.ts:48

Sets the address and port of the main Avalanche Client.

Parameters:

NameTypeDefaultDescription
hoststring-The hostname to resolve to reach the Avalanche Client RPC APIs.
portnumber-The port to resolve to reach the Avalanche Client RPC APIs.
protocolstring"http"The protocol string to use before a "://" in a request, ex: "http", "https", etc. Defaults to http The following special characters are removed from host and protocol &#,@+()$~%'":*?{} also less than and greater than signs

Returns: void


setAuthToken

setAuthToken(auth: string): void

Defined in src/avalanche.ts:202

Sets the temporary auth token used for communicating with the node.

Parameters:

NameTypeDescription
authstringA temporary token provided by the node enabling access to the endpoints on the node.

Returns: void


setHRP

setHRP(hrp: string): void

Defined in src/avalanche.ts:133

Sets the the Human-Readable-Part of the network associated with this key.

Parameters:

NameTypeDescription
hrpstringString for the Human-Readable-Part of Bech32 addresses

Returns: void


setHeader

setHeader(key: string, value: string): void

Defined in src/avalanche.ts:143

Adds a new custom header to be included with all requests.

Parameters:

NameTypeDescription
keystringHeader name
valuestringHeader value

Returns: void


setNetworkID

setNetworkID(netID: number): void

Defined in src/avalanche.ts:116

Sets the networkID

Parameters:

NameType
netIDnumber

Returns: void


setRequestConfig

setRequestConfig(key: string, value: string | boolean): void

Defined in src/avalanche.ts:173

Adds a new custom config value to be included with all requests.

Parameters:

NameTypeDescription
keystringConfig name
valuestring | booleanConfig value

Returns: void