avalanchecore.avalanchecore-1
avalanche › AvalancheCore › AvalancheCore
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
AvalancheCore
Index
Constructors
Properties
Methods
- _setHeaders
- addAPI
- api
- delete
- get
- getHRP
- getHeaders
- getHost
- getIP
- getNetworkID
- getPort
- getProtocol
- getRequestConfig
- getURL
- patch
- post
- put
- removeAllHeaders
- removeAllRequestConfigs
- removeHeader
- removeRequestConfig
- setAddress
- setAuthToken
- setHRP
- setHeader
- setNetworkID
- setRequestConfig
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:
Name | Type | Default | Description |
---|---|---|---|
host | string | - | The hostname to resolve to reach the Avalanche Client APIs |
port | number | - | The port to resolve to reach the Avalanche Client APIs |
protocol | string | "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:
- [ k: string]: APIBase
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:
Name | Type |
---|---|
headers | any |
Returns: AxiosRequestHeaders
addAPI
▸ addAPI‹GA›(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:
Name | Type | Default | Description |
---|---|---|---|
apiName | string | - | A label for referencing the API in the future |
ConstructorFN | object | - | A reference to the class which instantiates the API |
baseurl | string | undefined | Path to resolve to reach the API |
...args | any[] | - | - |
Returns: void
api
▸ api‹GA›(apiName
: string): GA
Defined in src/avalanche.ts:260
Retrieves a reference to an API by its apiName label.
Type parameters:
▪ GA: APIBase
Parameters:
Name | Type | Description |
---|---|---|
apiName | string | Name 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:
Name | Type | Default | Description |
---|---|---|---|
baseurl | string | - | Path to the API |
getdata | object | - | Object containing the key value pairs sent in DELETE |
headers | object | {} | An array HTTP Request Headers |
axiosConfig | AxiosRequestConfig | undefined | Configuration 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:
Name | Type | Default | Description |
---|---|---|---|
baseurl | string | - | Path to the api |
getdata | object | - | Object containing the key value pairs sent in GET |
headers | object | {} | An array HTTP Request Headers |
axiosConfig | AxiosRequestConfig | undefined | Configuration 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:
Name | Type | Default | Description |
---|---|---|---|
baseurl | string | - | Path to the baseurl |
getdata | object | - | Object containing the key value pairs sent in PATCH |
postdata | string | object | ArrayBuffer | ArrayBufferView | - | Object containing the key value pairs sent in PATCH |
headers | object | {} | An array HTTP Request Headers |
axiosConfig | AxiosRequestConfig | undefined | Configuration 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:
Name | Type | Default | Description |
---|---|---|---|
baseurl | string | - | Path to the API |
getdata | object | - | Object containing the key value pairs sent in POST |
postdata | string | object | ArrayBuffer | ArrayBufferView | - | Object containing the key value pairs sent in POST |
headers | object | {} | An array HTTP Request Headers |
axiosConfig | AxiosRequestConfig | undefined | Configuration 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:
Name | Type | Default | Description |
---|---|---|---|
baseurl | string | - | Path to the baseurl |
getdata | object | - | Object containing the key value pairs sent in PUT |
postdata | string | object | ArrayBuffer | ArrayBufferView | - | Object containing the key value pairs sent in PUT |
headers | object | {} | An array HTTP Request Headers |
axiosConfig | AxiosRequestConfig | undefined | Configuration 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:
Name | Type | Description |
---|---|---|
key | string | Header name |
Returns: void
removeRequestConfig
▸ removeRequestConfig(key
: string): void
Defined in src/avalanche.ts:182
Removes a previously added request config.
Parameters:
Name | Type | Description |
---|---|---|
key | string | Header 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:
Name | Type | Default | Description |
---|---|---|---|
host | string | - | The hostname to resolve to reach the Avalanche Client RPC APIs. |
port | number | - | The port to resolve to reach the Avalanche Client RPC APIs. |
protocol | string | "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:
Name | Type | Description |
---|---|---|
auth | string | A 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:
Name | Type | Description |
---|---|---|
hrp | string | String 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:
Name | Type | Description |
---|---|---|
key | string | Header name |
value | string | Header value |
Returns: void
setNetworkID
▸ setNetworkID(netID
: number): void
Defined in src/avalanche.ts:116
Sets the networkID
Parameters:
Name | Type |
---|---|
netID | number |
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:
Name | Type | Description |
---|---|---|
key | string | Config name |
value | string | boolean | Config value |
Returns: void