Skip to main content

avalanche.avalanche-1

avalancheAvalancheAvalanche

Class: Avalanche

AvalancheJS is middleware for interacting with Avalanche node RPC APIs.

Example usage:

const avalanche: Avalanche = new Avalanche("127.0.0.1", 9650, "https")

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

+ new Avalanche(host: string, port: number, protocol: string, networkID: number, XChainID: string, CChainID: string, hrp: string, skipinit: boolean): Avalanche

Overrides AvalancheCore.constructor

Defined in src/index.ts:88

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 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", "git", "ws", etc. Defaults to http
networkIDnumberDefaultNetworkIDSets the NetworkID of the class. Default DefaultNetworkID
XChainIDstringundefinedSets the blockchainID for the AVM. Will try to auto-detect, otherwise default "2eNy1mUFdmaxXNj1eQHUe7Np4gju9sJsEtWQ4MX3ToiNKuADed"
CChainIDstringundefinedSets the blockchainID for the EVM. Will try to auto-detect, otherwise default "2CA6j5zYzasynPsFeNoqWkmTCt3VScMvXUZHbfDJ8k3oGzAPtU"
hrpstringundefinedThe human-readable part of the bech32 addresses
skipinitbooleanfalseSkips creating the APIs. Defaults to false

Returns: Avalanche

Properties

Protected apis

apis: object

Inherited from AvalancheCore.apis

Defined in src/avalanche.ts:36

Type declaration:


Protected auth

auth: string = undefined

Inherited from AvalancheCore.auth

Defined in src/avalanche.ts:33


Protected headers

headers: object

Inherited from AvalancheCore.headers

Defined in src/avalanche.ts:34

Type declaration:

  • [ k: string]: string

Protected host

host: string

Inherited from AvalancheCore.host

Defined in src/avalanche.ts:30


Protected hrp

hrp: string = ""

Inherited from AvalancheCore.hrp

Defined in src/avalanche.ts:27


Protected ip

ip: string

Inherited from AvalancheCore.ip

Defined in src/avalanche.ts:29


Protected networkID

networkID: number = 0

Inherited from AvalancheCore.networkID

Defined in src/avalanche.ts:26


Protected port

port: number

Inherited from AvalancheCore.port

Defined in src/avalanche.ts:31


Protected protocol

protocol: string

Inherited from AvalancheCore.protocol

Defined in src/avalanche.ts:28


Protected requestConfig

requestConfig: AxiosRequestConfig

Inherited from AvalancheCore.requestConfig

Defined in src/avalanche.ts:35


Protected url

url: string

Inherited from AvalancheCore.url

Defined in src/avalanche.ts:32

Methods

Admin

Admin(): AdminAPI‹›

Defined in src/index.ts:42

Returns a reference to the Admin RPC.

Returns: AdminAPI‹›


Auth

Auth(): AuthAPI‹›

Defined in src/index.ts:47

Returns a reference to the Auth RPC.

Returns: AuthAPI‹›


CChain

CChain(): EVMAPI‹›

Defined in src/index.ts:52

Returns a reference to the EVMAPI RPC pointed at the C-Chain.

Returns: EVMAPI‹›


Health

Health(): HealthAPI‹›

Defined in src/index.ts:62

Returns a reference to the Health RPC for a node.

Returns: HealthAPI‹›


Index

Index(): IndexAPI‹›

Defined in src/index.ts:67

Returns a reference to the Index RPC for a node.

Returns: IndexAPI‹›


Info

Info(): InfoAPI‹›

Defined in src/index.ts:72

Returns a reference to the Info RPC for a node.

Returns: InfoAPI‹›


Metrics

Metrics(): MetricsAPI‹›

Defined in src/index.ts:77

Returns a reference to the Metrics RPC.

Returns: MetricsAPI‹›


NodeKeys

NodeKeys(): KeystoreAPI‹›

Defined in src/index.ts:83

Returns a reference to the Keystore RPC for a node. We label it "NodeKeys" to reduce confusion about what it's accessing.

Returns: KeystoreAPI‹›


PChain

PChain(): PlatformVMAPI‹›

Defined in src/index.ts:88

Returns a reference to the PlatformVM RPC pointed at the P-Chain.

Returns: PlatformVMAPI‹›


XChain

XChain(): AVMAPI‹›

Defined in src/index.ts:57

Returns a reference to the AVM RPC pointed at the X-Chain.

Returns: AVMAPI‹›


Protected _setHeaders

_setHeaders(headers: any): AxiosRequestHeaders

Inherited from AvalancheCore._setHeaders

Defined in src/avalanche.ts:206

Parameters:

NameType
headersany

Returns: AxiosRequestHeaders


addAPI

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

Inherited from AvalancheCore.addAPI

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

Inherited from AvalancheCore.api

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

Inherited from AvalancheCore.delete

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

Inherited from AvalancheCore.get

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

Inherited from AvalancheCore.getHRP

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

Inherited from AvalancheCore.getHeaders

Defined in src/avalanche.ts:101

Returns the custom headers

Returns: object


getHost

getHost(): string

Inherited from AvalancheCore.getHost

Defined in src/avalanche.ts:81

Returns the host for the Avalanche node.

Returns: string


getIP

getIP(): string

Inherited from AvalancheCore.getIP

Defined in src/avalanche.ts:86

Returns the IP for the Avalanche node.

Returns: string


getNetworkID

getNetworkID(): number

Inherited from AvalancheCore.getNetworkID

Defined in src/avalanche.ts:111

Returns the networkID

Returns: number


getPort

getPort(): number

Inherited from AvalancheCore.getPort

Defined in src/avalanche.ts:91

Returns the port for the Avalanche node.

Returns: number


getProtocol

getProtocol(): string

Inherited from AvalancheCore.getProtocol

Defined in src/avalanche.ts:76

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

Returns: string


getRequestConfig

getRequestConfig(): AxiosRequestConfig

Inherited from AvalancheCore.getRequestConfig

Defined in src/avalanche.ts:106

Returns the custom request config

Returns: AxiosRequestConfig


getURL

getURL(): string

Inherited from AvalancheCore.getURL

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

Inherited from AvalancheCore.patch

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

Inherited from AvalancheCore.post

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

Inherited from AvalancheCore.put

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

Inherited from AvalancheCore.removeAllHeaders

Defined in src/avalanche.ts:159

Removes all headers.

Returns: void


removeAllRequestConfigs

removeAllRequestConfigs(): void

Inherited from AvalancheCore.removeAllRequestConfigs

Defined in src/avalanche.ts:189

Removes all request configs.

Returns: void


removeHeader

removeHeader(key: string): void

Inherited from AvalancheCore.removeHeader

Defined in src/avalanche.ts:152

Removes a previously added custom header.

Parameters:

NameTypeDescription
keystringHeader name

Returns: void


removeRequestConfig

removeRequestConfig(key: string): void

Inherited from AvalancheCore.removeRequestConfig

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

Inherited from AvalancheCore.setAddress

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

Inherited from AvalancheCore.setAuthToken

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

Inherited from AvalancheCore.setHRP

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

Inherited from AvalancheCore.setHeader

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

Inherited from AvalancheCore.setNetworkID

Defined in src/avalanche.ts:116

Sets the networkID

Parameters:

NameType
netIDnumber

Returns: void


setRequestConfig

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

Inherited from AvalancheCore.setRequestConfig

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