@fewcha/aptos
Version:
1,629 lines (1,522 loc) • 284 kB
TypeScript
import nacl from 'tweetnacl';
declare type Seq<T> = T[];
declare type Uint8 = number;
declare type Uint16 = number;
declare type Uint32 = number;
declare type Uint64 = bigint;
declare type Uint128 = bigint;
declare type Uint256 = bigint;
declare type AnyNumber = bigint | number;
declare type Bytes = Uint8Array;
declare class Serializer {
private buffer;
private offset;
constructor();
private ensureBufferWillHandleSize;
protected serialize(values: Bytes): void;
private serializeWithFunction;
/**
* Serializes a string. UTF8 string is supported. Serializes the string's bytes length "l" first,
* and then serializes "l" bytes of the string content.
*
* BCS layout for "string": string_length | string_content. string_length is the bytes length of
* the string that is uleb128 encoded. string_length is a u32 integer.
*
* @example
* ```ts
* const serializer = new Serializer();
* serializer.serializeStr("çå∞≠¢õß∂ƒ∫");
* assert(serializer.getBytes() === new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,
* 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]));
* ```
*/
serializeStr(value: string): void;
/**
* Serializes an array of bytes.
*
* BCS layout for "bytes": bytes_length | bytes. bytes_length is the length of the bytes array that is
* uleb128 encoded. bytes_length is a u32 integer.
*/
serializeBytes(value: Bytes): void;
/**
* Serializes an array of bytes with known length. Therefore length doesn't need to be
* serialized to help deserialization. When deserializing, the number of
* bytes to deserialize needs to be passed in.
*/
serializeFixedBytes(value: Bytes): void;
/**
* Serializes a boolean value.
*
* BCS layout for "boolean": One byte. "0x01" for True and "0x00" for False.
*/
serializeBool(value: boolean): void;
/**
* Serializes a uint8 number.
*
* BCS layout for "uint8": One byte. Binary format in little-endian representation.
*/
serializeU8(value: Uint8): void;
/**
* Serializes a uint16 number.
*
* BCS layout for "uint16": Two bytes. Binary format in little-endian representation.
* @example
* ```ts
* const serializer = new Serializer();
* serializer.serializeU16(4660);
* assert(serializer.getBytes() === new Uint8Array([0x34, 0x12]));
* ```
*/
serializeU16(value: Uint16): void;
/**
* Serializes a uint32 number.
*
* BCS layout for "uint32": Four bytes. Binary format in little-endian representation.
* @example
* ```ts
* const serializer = new Serializer();
* serializer.serializeU32(305419896);
* assert(serializer.getBytes() === new Uint8Array([0x78, 0x56, 0x34, 0x12]));
* ```
*/
serializeU32(value: Uint32): void;
/**
* Serializes a uint64 number.
*
* BCS layout for "uint64": Eight bytes. Binary format in little-endian representation.
* @example
* ```ts
* const serializer = new Serializer();
* serializer.serializeU64(1311768467750121216);
* assert(serializer.getBytes() === new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));
* ```
*/
serializeU64(value: AnyNumber): void;
/**
* Serializes a uint128 number.
*
* BCS layout for "uint128": Sixteen bytes. Binary format in little-endian representation.
*/
serializeU128(value: AnyNumber): void;
/**
* Serializes a uint256 number.
*
* BCS layout for "uint256": Sixteen bytes. Binary format in little-endian representation.
*/
serializeU256(value: AnyNumber): void;
/**
* Serializes a uint32 number with uleb128.
*
* BCS use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
*/
serializeU32AsUleb128(val: Uint32): void;
/**
* Returns the buffered bytes
*/
getBytes(): Bytes;
}
declare class Deserializer {
private buffer;
private offset;
constructor(data: Bytes);
private read;
/**
* Deserializes a string. UTF8 string is supported. Reads the string's bytes length "l" first,
* and then reads "l" bytes of content. Decodes the byte array into a string.
*
* BCS layout for "string": string_length | string_content. string_length is the bytes length of
* the string that is uleb128 encoded. string_length is a u32 integer.
*
* @example
* ```ts
* const deserializer = new Deserializer(new Uint8Array([24, 0xc3, 0xa7, 0xc3, 0xa5, 0xe2, 0x88, 0x9e,
* 0xe2, 0x89, 0xa0, 0xc2, 0xa2, 0xc3, 0xb5, 0xc3, 0x9f, 0xe2, 0x88, 0x82, 0xc6, 0x92, 0xe2, 0x88, 0xab]));
* assert(deserializer.deserializeStr() === "çå∞≠¢õß∂ƒ∫");
* ```
*/
deserializeStr(): string;
/**
* Deserializes an array of bytes.
*
* BCS layout for "bytes": bytes_length | bytes. bytes_length is the length of the bytes array that is
* uleb128 encoded. bytes_length is a u32 integer.
*/
deserializeBytes(): Bytes;
/**
* Deserializes an array of bytes. The number of bytes to read is already known.
*
*/
deserializeFixedBytes(len: number): Bytes;
/**
* Deserializes a boolean value.
*
* BCS layout for "boolean": One byte. "0x01" for True and "0x00" for False.
*/
deserializeBool(): boolean;
/**
* Deserializes a uint8 number.
*
* BCS layout for "uint8": One byte. Binary format in little-endian representation.
*/
deserializeU8(): Uint8;
/**
* Deserializes a uint16 number.
*
* BCS layout for "uint16": Two bytes. Binary format in little-endian representation.
* @example
* ```ts
* const deserializer = new Deserializer(new Uint8Array([0x34, 0x12]));
* assert(deserializer.deserializeU16() === 4660);
* ```
*/
deserializeU16(): Uint16;
/**
* Deserializes a uint32 number.
*
* BCS layout for "uint32": Four bytes. Binary format in little-endian representation.
* @example
* ```ts
* const deserializer = new Deserializer(new Uint8Array([0x78, 0x56, 0x34, 0x12]));
* assert(deserializer.deserializeU32() === 305419896);
* ```
*/
deserializeU32(): Uint32;
/**
* Deserializes a uint64 number.
*
* BCS layout for "uint64": Eight bytes. Binary format in little-endian representation.
* @example
* ```ts
* const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12]));
* assert(deserializer.deserializeU64() === 1311768467750121216);
* ```
*/
deserializeU64(): Uint64;
/**
* Deserializes a uint128 number.
*
* BCS layout for "uint128": Sixteen bytes. Binary format in little-endian representation.
*/
deserializeU128(): Uint128;
/**
* Deserializes a uint256 number.
*
* BCS layout for "uint256": Thirty-two bytes. Binary format in little-endian representation.
*/
deserializeU256(): Uint256;
/**
* Deserializes a uleb128 encoded uint32 number.
*
* BCS use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values
*/
deserializeUleb128AsU32(): Uint32;
}
interface Serializable {
serialize(serializer: Serializer): void;
}
/**
* Serializes a vector values that are "Serializable".
*/
declare function serializeVector<T extends Serializable>(value: Seq<T>, serializer: Serializer): void;
/**
* Serializes a vector with specified item serialization function.
* Very dynamic function and bypasses static typechecking.
*/
declare function serializeVectorWithFunc(value: any[], func: string): Bytes;
/**
* Deserializes a vector of values.
*/
declare function deserializeVector(deserializer: Deserializer, cls: any): any[];
declare function bcsToBytes<T extends Serializable>(value: T): Bytes;
declare function bcsSerializeUint64(value: AnyNumber): Bytes;
declare function bcsSerializeU8(value: Uint8): Bytes;
declare function bcsSerializeU16(value: Uint16): Bytes;
declare function bcsSerializeU32(value: Uint32): Bytes;
declare function bcsSerializeU128(value: AnyNumber): Bytes;
declare function bcsSerializeU256(value: AnyNumber): Bytes;
declare function bcsSerializeBool(value: boolean): Bytes;
declare function bcsSerializeStr(value: string): Bytes;
declare function bcsSerializeBytes(value: Bytes): Bytes;
declare function bcsSerializeFixedBytes(value: Bytes): Bytes;
type index$2_Seq<T> = Seq<T>;
type index$2_Uint8 = Uint8;
type index$2_Uint16 = Uint16;
type index$2_Uint32 = Uint32;
type index$2_Uint64 = Uint64;
type index$2_Uint128 = Uint128;
type index$2_Uint256 = Uint256;
type index$2_AnyNumber = AnyNumber;
type index$2_Bytes = Bytes;
type index$2_Serializer = Serializer;
declare const index$2_Serializer: typeof Serializer;
type index$2_Deserializer = Deserializer;
declare const index$2_Deserializer: typeof Deserializer;
declare const index$2_serializeVector: typeof serializeVector;
declare const index$2_serializeVectorWithFunc: typeof serializeVectorWithFunc;
declare const index$2_deserializeVector: typeof deserializeVector;
declare const index$2_bcsToBytes: typeof bcsToBytes;
declare const index$2_bcsSerializeUint64: typeof bcsSerializeUint64;
declare const index$2_bcsSerializeU8: typeof bcsSerializeU8;
declare const index$2_bcsSerializeU16: typeof bcsSerializeU16;
declare const index$2_bcsSerializeU32: typeof bcsSerializeU32;
declare const index$2_bcsSerializeU128: typeof bcsSerializeU128;
declare const index$2_bcsSerializeU256: typeof bcsSerializeU256;
declare const index$2_bcsSerializeBool: typeof bcsSerializeBool;
declare const index$2_bcsSerializeStr: typeof bcsSerializeStr;
declare const index$2_bcsSerializeBytes: typeof bcsSerializeBytes;
declare const index$2_bcsSerializeFixedBytes: typeof bcsSerializeFixedBytes;
declare namespace index$2 {
export {
index$2_Seq as Seq,
index$2_Uint8 as Uint8,
index$2_Uint16 as Uint16,
index$2_Uint32 as Uint32,
index$2_Uint64 as Uint64,
index$2_Uint128 as Uint128,
index$2_Uint256 as Uint256,
index$2_AnyNumber as AnyNumber,
index$2_Bytes as Bytes,
index$2_Serializer as Serializer,
index$2_Deserializer as Deserializer,
index$2_serializeVector as serializeVector,
index$2_serializeVectorWithFunc as serializeVectorWithFunc,
index$2_deserializeVector as deserializeVector,
index$2_bcsToBytes as bcsToBytes,
index$2_bcsSerializeUint64 as bcsSerializeUint64,
index$2_bcsSerializeU8 as bcsSerializeU8,
index$2_bcsSerializeU16 as bcsSerializeU16,
index$2_bcsSerializeU32 as bcsSerializeU32,
index$2_bcsSerializeU128 as bcsSerializeU128,
index$2_bcsSerializeU256 as bcsSerializeU256,
index$2_bcsSerializeBool as bcsSerializeBool,
index$2_bcsSerializeStr as bcsSerializeStr,
index$2_bcsSerializeBytes as bcsSerializeBytes,
index$2_bcsSerializeFixedBytes as bcsSerializeFixedBytes,
};
}
/**
* A configuration object we can pass with the request to the server.
*
* @param TOKEN - an auth token to send with the request
* @param HEADERS - extra headers we want to send with the request
* @param WITH_CREDENTIALS - whether to carry cookies. By default, it is set to true and cookies will be sent
*/
declare type ClientConfig = {
TOKEN?: string;
HEADERS?: Record<string, string | number | boolean>;
WITH_CREDENTIALS?: boolean;
};
/**
* The API request type
*
* @param url - the url to make the request to, i.e https://fullnode.aptoslabs.devnet.com/v1
* @param method - the request method "GET" | "POST"
* @param endpoint (optional) - the endpoint to make the request to, i.e transactions
* @param body (optional) - the body of the request
* @param contentType (optional) - the content type to set the `content-type` header to,
* by default is set to `application/json`
* @param params (optional) - query params to add to the request
* @param originMethod (optional) - the local method the request came from
* @param overrides (optional) - a `ClientConfig` object type to override request data
*/
declare type AptosRequest = {
url: string;
method: "GET" | "POST";
endpoint?: string;
body?: any;
contentType?: string;
params?: Record<string, string | AnyNumber | boolean | undefined>;
originMethod?: string;
overrides?: ClientConfig;
};
/**
* The API response type
*
* @param status - the response status. i.e 200
* @param statusText - the response message
* @param data the response data
* @param url the url the request was made to
* @param headers the response headers
* @param config (optional) - the request object
* @param request (optional) - the request object
*/
interface AptosResponse<Req, Res> {
status: number;
statusText: string;
data: Res;
url: string;
headers: any;
config?: any;
request?: Req;
}
/**
* The type returned from an API error
*
* @param name - the error name "AptosApiError"
* @param url the url the request was made to
* @param status - the response status. i.e 400
* @param statusText - the response message
* @param data the response data
* @param request - the AptosRequest
*/
declare class AptosApiError extends Error {
readonly url: string;
readonly status: number;
readonly statusText: string;
readonly data: any;
readonly request: AptosRequest;
constructor(request: AptosRequest, response: AptosResponse<any, any>, message: string);
}
/**
* The main function to use when doing an API request.
* Wraps axios error response with AptosApiError
*
* @param options AptosRequest
* @returns the response or AptosApiError
*/
declare function aptosRequest<Req, Res>(options: AptosRequest): Promise<AptosResponse<Req, Res>>;
declare type GetRequestOptions = Omit<AptosRequest, "body" | "method">;
/**
* Main function to do a Get request
*
* @param options GetRequestOptions
* @returns
*/
declare function get<Req, Res>(options: GetRequestOptions): Promise<AptosResponse<Req, Res>>;
declare type PostRequestOptions = Omit<AptosRequest, "method">;
/**
* Main function to do a Post request
*
* @param options PostRequestOptions
* @returns
*/
declare function post<Req, Res>(options: PostRequestOptions): Promise<AptosResponse<Req, Res>>;
declare enum Network {
MAINNET = "mainnet",
TESTNET = "testnet",
DEVNET = "devnet"
}
interface CustomEndpoints {
fullnodeUrl: string;
indexerUrl?: string;
}
declare type ApiRequestOptions = {
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
readonly url: string;
readonly path?: Record<string, any>;
readonly cookies?: Record<string, any>;
readonly headers?: Record<string, any>;
readonly query?: Record<string, any>;
readonly formData?: Record<string, any>;
readonly body?: any;
readonly mediaType?: string;
readonly responseHeader?: string;
readonly errors?: Record<number, string>;
};
declare class CancelError extends Error {
constructor(message: string);
get isCancelled(): boolean;
}
interface OnCancel {
readonly isResolved: boolean;
readonly isRejected: boolean;
readonly isCancelled: boolean;
(cancelHandler: () => void): void;
}
declare class CancelablePromise<T> implements Promise<T> {
readonly [Symbol.toStringTag]: string;
private _isResolved;
private _isRejected;
private _isCancelled;
private readonly _cancelHandlers;
private readonly _promise;
private _resolve?;
private _reject?;
constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, onCancel: OnCancel) => void);
then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
catch<TResult = never>(onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
finally(onFinally?: (() => void) | null): Promise<T>;
cancel(): void;
get isCancelled(): boolean;
}
declare type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
declare type Headers = Record<string, string>;
declare type OpenAPIConfig = {
BASE: string;
VERSION: string;
WITH_CREDENTIALS: boolean;
CREDENTIALS: 'include' | 'omit' | 'same-origin';
TOKEN?: string | Resolver<string>;
USERNAME?: string | Resolver<string>;
PASSWORD?: string | Resolver<string>;
HEADERS?: Headers | Resolver<Headers>;
ENCODE_PATH?: (path: string) => string;
};
declare const OpenAPI: OpenAPIConfig;
declare abstract class BaseHttpRequest {
readonly config: OpenAPIConfig;
constructor(config: OpenAPIConfig);
abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;
}
/**
* All bytes (Vec<u8>) data is represented as hex-encoded string prefixed with `0x` and fulfilled with
* two hex digits per byte.
*
* Unlike the `Address` type, HexEncodedBytes will not trim any zeros.
*
*/
declare type HexEncodedBytes = string;
/**
* A string containing a 64-bit unsigned integer.
*
* We represent u64 values as a string to ensure compatibility with languages such
* as JavaScript that do not parse u64s in JSON natively.
*
*/
declare type U64$1 = string;
/**
* Account data
*
* A simplified version of the onchain Account resource
*/
declare type AccountData = {
sequence_number: U64$1;
authentication_key: HexEncodedBytes;
};
/**
* A hex encoded 32 byte Aptos account address.
*
* This is represented in a string as a 64 character hex string, sometimes
* shortened by stripping leading 0s, and adding a 0x.
*
* For example, address 0x0000000000000000000000000000000000000000000000000000000000000001 is represented as 0x1.
*
*/
declare type Address = string;
declare type IdentifierWrapper = string;
declare type MoveAbility = string;
/**
* Move function generic type param
*/
declare type MoveFunctionGenericTypeParam = {
/**
* Move abilities tied to the generic type param and associated with the function that uses it
*/
constraints: Array<MoveAbility>;
};
/**
* Move function visibility
*/
declare enum MoveFunctionVisibility {
PRIVATE = "private",
PUBLIC = "public",
FRIEND = "friend"
}
/**
* String representation of an on-chain Move type tag that is exposed in transaction payload.
* Values:
* - bool
* - u8
* - u16
* - u32
* - u64
* - u128
* - u256
* - address
* - signer
* - vector: `vector<{non-reference MoveTypeId}>`
* - struct: `{address}::{module_name}::{struct_name}::<{generic types}>`
*
* Vector type value examples:
* - `vector<u8>`
* - `vector<vector<u64>>`
* - `vector<0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>>`
*
* Struct type value examples:
* - `0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>
* - `0x1::account::Account`
*
* Note:
* 1. Empty chars should be ignored when comparing 2 struct tag ids.
* 2. When used in an URL path, should be encoded by url-encoding (AKA percent-encoding).
*
*/
declare type MoveType = string;
/**
* Move function
*/
declare type MoveFunction = {
name: IdentifierWrapper;
visibility: MoveFunctionVisibility;
/**
* Whether the function can be called as an entry function directly in a transaction
*/
is_entry: boolean;
/**
* Whether the function is a view function or not
*/
is_view: boolean;
/**
* Generic type params associated with the Move function
*/
generic_type_params: Array<MoveFunctionGenericTypeParam>;
/**
* Parameters associated with the move function
*/
params: Array<MoveType>;
/**
* Return type of the function
*/
return: Array<MoveType>;
};
/**
* Move module id is a string representation of Move module.
*
* Format: `{address}::{module name}`
*
* `address` should be hex-encoded 32 byte account address that is prefixed with `0x`.
*
* Module name is case-sensitive.
*
*/
declare type MoveModuleId = string;
/**
* Move struct field
*/
declare type MoveStructField = {
name: IdentifierWrapper;
type: MoveType;
};
/**
* Move generic type param
*/
declare type MoveStructGenericTypeParam = {
/**
* Move abilities tied to the generic type param and associated with the type that uses it
*/
constraints: Array<MoveAbility>;
};
/**
* A move struct
*/
declare type MoveStruct = {
name: IdentifierWrapper;
/**
* Whether the struct is a native struct of Move
*/
is_native: boolean;
/**
* Abilities associated with the struct
*/
abilities: Array<MoveAbility>;
/**
* Generic types associated with the struct
*/
generic_type_params: Array<MoveStructGenericTypeParam>;
/**
* Fields associated with the struct
*/
fields: Array<MoveStructField>;
};
/**
* A Move module
*/
declare type MoveModule = {
address: Address;
name: IdentifierWrapper;
/**
* Friends of the module
*/
friends: Array<MoveModuleId>;
/**
* Public functions of the module
*/
exposed_functions: Array<MoveFunction>;
/**
* Structs of the module
*/
structs: Array<MoveStruct>;
};
/**
* Move module bytecode along with it's ABI
*/
declare type MoveModuleBytecode = {
bytecode: HexEncodedBytes;
abi?: MoveModule;
};
/**
* String representation of a MoveStructTag (on-chain Move struct type). This exists so you
* can specify MoveStructTags as path / query parameters, e.g. for get_events_by_event_handle.
*
* It is a combination of:
* 1. `move_module_address`, `module_name` and `struct_name`, all joined by `::`
* 2. `struct generic type parameters` joined by `, `
*
* Examples:
* * `0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>`
* * `0x1::account::Account`
*
* Note:
* 1. Empty chars should be ignored when comparing 2 struct tag ids.
* 2. When used in an URL path, should be encoded by url-encoding (AKA percent-encoding).
*
* See [doc](https://aptos.dev/concepts/accounts) for more details.
*
*/
declare type MoveStructTag = string;
/**
* This is a JSON representation of some data within an account resource. More specifically,
* it is a map of strings to arbitrary JSON values / objects, where the keys are top level
* fields within the given resource.
*
* To clarify, you might query for 0x1::account::Account and see the example data.
*
* Move `bool` type value is serialized into `boolean`.
*
* Move `u8`, `u16` and `u32` type value is serialized into `integer`.
*
* Move `u64`, `u128` and `u256` type value is serialized into `string`.
*
* Move `address` type value (32 byte Aptos account address) is serialized into a HexEncodedBytes string.
* For example:
* - `0x1`
* - `0x1668f6be25668c1a17cd8caf6b8d2f25`
*
* Move `vector` type value is serialized into `array`, except `vector<u8>` which is serialized into a
* HexEncodedBytes string with `0x` prefix.
* For example:
* - `vector<u64>{255, 255}` => `["255", "255"]`
* - `vector<u8>{255, 255}` => `0xffff`
*
* Move `struct` type value is serialized into `object` that looks like this (except some Move stdlib types, see the following section):
* ```json
* {
* field1_name: field1_value,
* field2_name: field2_value,
* ......
* }
* ```
*
* For example:
* `{ "created": "0xa550c18", "role_id": "0" }`
*
* **Special serialization for Move stdlib types**:
* - [0x1::string::String](https://github.com/aptos-labs/aptos-core/blob/main/language/move-stdlib/docs/ascii.md)
* is serialized into `string`. For example, struct value `0x1::string::String{bytes: b"Hello World!"}`
* is serialized as `"Hello World!"` in JSON.
*
*/
declare type MoveStructValue = {};
/**
* A parsed Move resource
*/
declare type MoveResource = {
type: MoveStructTag;
data: MoveStructValue;
};
/**
* Representation of a StateKey as a hex string. This is used for cursor based pagination.
*
*/
declare type StateKeyWrapper = string;
declare class AccountsService {
readonly httpRequest: BaseHttpRequest;
constructor(httpRequest: BaseHttpRequest);
/**
* Get account
* Return the authentication key and the sequence number for an account
* address. Optionally, a ledger version can be specified. If the ledger
* version is not specified in the request, the latest ledger version is used.
* @param address Address of account with or without a `0x` prefix
* @param ledgerVersion Ledger version to get state of account
*
* If not provided, it will be the latest version
* @returns AccountData
* @throws ApiError
*/
getAccount(address: Address, ledgerVersion?: U64$1): CancelablePromise<AccountData>;
/**
* Get account resources
* Retrieves all account resources for a given account and a specific ledger version. If the
* ledger version is not specified in the request, the latest ledger version is used.
*
* The Aptos nodes prune account state history, via a configurable time window.
* If the requested ledger version has been pruned, the server responds with a 410.
* @param address Address of account with or without a `0x` prefix
* @param ledgerVersion Ledger version to get state of account
*
* If not provided, it will be the latest version
* @param start Cursor specifying where to start for pagination
*
* This cursor cannot be derived manually client-side. Instead, you must
* call this endpoint once without this query parameter specified, and
* then use the cursor returned in the X-Aptos-Cursor header in the
* response.
* @param limit Max number of account resources to retrieve
*
* If not provided, defaults to default page size.
* @returns MoveResource
* @throws ApiError
*/
getAccountResources(address: Address, ledgerVersion?: U64$1, start?: StateKeyWrapper, limit?: number): CancelablePromise<Array<MoveResource>>;
/**
* Get account modules
* Retrieves all account modules' bytecode for a given account at a specific ledger version.
* If the ledger version is not specified in the request, the latest ledger version is used.
*
* The Aptos nodes prune account state history, via a configurable time window.
* If the requested ledger version has been pruned, the server responds with a 410.
* @param address Address of account with or without a `0x` prefix
* @param ledgerVersion Ledger version to get state of account
*
* If not provided, it will be the latest version
* @param start Cursor specifying where to start for pagination
*
* This cursor cannot be derived manually client-side. Instead, you must
* call this endpoint once without this query parameter specified, and
* then use the cursor returned in the X-Aptos-Cursor header in the
* response.
* @param limit Max number of account modules to retrieve
*
* If not provided, defaults to default page size.
* @returns MoveModuleBytecode
* @throws ApiError
*/
getAccountModules(address: Address, ledgerVersion?: U64$1, start?: StateKeyWrapper, limit?: number): CancelablePromise<Array<MoveModuleBytecode>>;
/**
* Get account resource
* Retrieves an individual resource from a given account and at a specific ledger version. If the
* ledger version is not specified in the request, the latest ledger version is used.
*
* The Aptos nodes prune account state history, via a configurable time window.
* If the requested ledger version has been pruned, the server responds with a 410.
* @param address Address of account with or without a `0x` prefix
* @param resourceType Name of struct to retrieve e.g. `0x1::account::Account`
* @param ledgerVersion Ledger version to get state of account
*
* If not provided, it will be the latest version
* @returns MoveResource
* @throws ApiError
*/
getAccountResource(address: Address, resourceType: MoveStructTag, ledgerVersion?: U64$1): CancelablePromise<MoveResource>;
/**
* Get account module
* Retrieves an individual module from a given account and at a specific ledger version. If the
* ledger version is not specified in the request, the latest ledger version is used.
*
* The Aptos nodes prune account state history, via a configurable time window.
* If the requested ledger version has been pruned, the server responds with a 410.
* @param address Address of account with or without a `0x` prefix
* @param moduleName Name of module to retrieve e.g. `coin`
* @param ledgerVersion Ledger version to get state of account
*
* If not provided, it will be the latest version
* @returns MoveModuleBytecode
* @throws ApiError
*/
getAccountModule(address: Address, moduleName: IdentifierWrapper, ledgerVersion?: U64$1): CancelablePromise<MoveModuleBytecode>;
}
declare type HashValue = string;
declare type EventGuid = {
creation_number: U64$1;
account_address: Address;
};
/**
* An event from a transaction
*/
declare type Event = {
guid: EventGuid;
sequence_number: U64$1;
type: MoveType;
/**
* The JSON representation of the event
*/
data: any;
};
/**
* Delete a module
*/
declare type DeleteModule = {
address: Address;
/**
* State key hash
*/
state_key_hash: string;
module: MoveModuleId;
};
declare type WriteSetChange_DeleteModule = ({
type: string;
} & DeleteModule);
/**
* Delete a resource
*/
declare type DeleteResource = {
address: Address;
/**
* State key hash
*/
state_key_hash: string;
resource: MoveStructTag;
};
declare type WriteSetChange_DeleteResource = ({
type: string;
} & DeleteResource);
/**
* Deleted table data
*/
declare type DeletedTableData = {
/**
* Deleted key
*/
key: any;
/**
* Deleted key type
*/
key_type: string;
};
/**
* Delete a table item
*/
declare type DeleteTableItem = {
state_key_hash: string;
handle: HexEncodedBytes;
key: HexEncodedBytes;
data?: DeletedTableData;
};
declare type WriteSetChange_DeleteTableItem = ({
type: string;
} & DeleteTableItem);
/**
* Write a new module or update an existing one
*/
declare type WriteModule = {
address: Address;
/**
* State key hash
*/
state_key_hash: string;
data: MoveModuleBytecode;
};
declare type WriteSetChange_WriteModule = ({
type: string;
} & WriteModule);
/**
* Write a resource or update an existing one
*/
declare type WriteResource = {
address: Address;
/**
* State key hash
*/
state_key_hash: string;
data: MoveResource;
};
declare type WriteSetChange_WriteResource = ({
type: string;
} & WriteResource);
/**
* Decoded table data
*/
declare type DecodedTableData = {
/**
* Key of table in JSON
*/
key: any;
/**
* Type of key
*/
key_type: string;
/**
* Value of table in JSON
*/
value: any;
/**
* Type of value
*/
value_type: string;
};
/**
* Change set to write a table item
*/
declare type WriteTableItem = {
state_key_hash: string;
handle: HexEncodedBytes;
key: HexEncodedBytes;
value: HexEncodedBytes;
data?: DecodedTableData;
};
declare type WriteSetChange_WriteTableItem = ({
type: string;
} & WriteTableItem);
/**
* A final state change of a transaction on a resource or module
*/
declare type WriteSetChange = (WriteSetChange_DeleteModule | WriteSetChange_DeleteResource | WriteSetChange_DeleteTableItem | WriteSetChange_WriteModule | WriteSetChange_WriteResource | WriteSetChange_WriteTableItem);
/**
* A block metadata transaction
*
* This signifies the beginning of a block, and contains information
* about the specific block
*/
declare type BlockMetadataTransaction = {
version: U64$1;
hash: HashValue;
state_change_hash: HashValue;
event_root_hash: HashValue;
state_checkpoint_hash?: HashValue;
gas_used: U64$1;
/**
* Whether the transaction was successful
*/
success: boolean;
/**
* The VM status of the transaction, can tell useful information in a failure
*/
vm_status: string;
accumulator_root_hash: HashValue;
/**
* Final state of resources changed by the transaction
*/
changes: Array<WriteSetChange>;
id: HashValue;
epoch: U64$1;
round: U64$1;
/**
* The events emitted at the block creation
*/
events: Array<Event>;
/**
* Previous block votes
*/
previous_block_votes_bitvec: Array<number>;
proposer: Address;
/**
* The indices of the proposers who failed to propose
*/
failed_proposer_indices: Array<number>;
timestamp: U64$1;
};
declare type Transaction_BlockMetadataTransaction = ({
type: string;
} & BlockMetadataTransaction);
declare type DirectWriteSet = {
changes: Array<WriteSetChange>;
events: Array<Event>;
};
declare type WriteSet_DirectWriteSet = ({
type: string;
} & DirectWriteSet);
/**
* Move script bytecode
*/
declare type MoveScriptBytecode = {
bytecode: HexEncodedBytes;
abi?: MoveFunction;
};
/**
* Payload which runs a script that can run multiple functions
*/
declare type ScriptPayload = {
code: MoveScriptBytecode;
/**
* Type arguments of the function
*/
type_arguments: Array<MoveType>;
/**
* Arguments of the function
*/
arguments: Array<any>;
};
declare type ScriptWriteSet = {
execute_as: Address;
script: ScriptPayload;
};
declare type WriteSet_ScriptWriteSet = ({
type: string;
} & ScriptWriteSet);
/**
* The associated writeset with a payload
*/
declare type WriteSet$1 = (WriteSet_ScriptWriteSet | WriteSet_DirectWriteSet);
/**
* A writeset payload, used only for genesis
*/
declare type WriteSetPayload = {
write_set: WriteSet$1;
};
declare type GenesisPayload_WriteSetPayload = ({
type: string;
} & WriteSetPayload);
/**
* The writeset payload of the Genesis transaction
*/
declare type GenesisPayload = GenesisPayload_WriteSetPayload;
/**
* The genesis transaction
*
* This only occurs at the genesis transaction (version 0)
*/
declare type GenesisTransaction = {
version: U64$1;
hash: HashValue;
state_change_hash: HashValue;
event_root_hash: HashValue;
state_checkpoint_hash?: HashValue;
gas_used: U64$1;
/**
* Whether the transaction was successful
*/
success: boolean;
/**
* The VM status of the transaction, can tell useful information in a failure
*/
vm_status: string;
accumulator_root_hash: HashValue;
/**
* Final state of resources changed by the transaction
*/
changes: Array<WriteSetChange>;
payload: GenesisPayload;
/**
* Events emitted during genesis
*/
events: Array<Event>;
};
declare type Transaction_GenesisTransaction = ({
type: string;
} & GenesisTransaction);
/**
* Entry function id is string representation of a entry function defined on-chain.
*
* Format: `{address}::{module name}::{function name}`
*
* Both `module name` and `function name` are case-sensitive.
*
*/
declare type EntryFunctionId = string;
/**
* Payload which runs a single entry function
*/
declare type EntryFunctionPayload = {
function: EntryFunctionId;
/**
* Type arguments of the function
*/
type_arguments: Array<MoveType>;
/**
* Arguments of the function
*/
arguments: Array<any>;
};
declare type TransactionPayload_EntryFunctionPayload = ({
type: string;
} & EntryFunctionPayload);
declare type ModuleBundlePayload = {
modules: Array<MoveModuleBytecode>;
};
declare type TransactionPayload_ModuleBundlePayload = ({
type: string;
} & ModuleBundlePayload);
declare type MultisigTransactionPayload = EntryFunctionPayload;
/**
* A multisig transaction that allows an owner of a multisig account to execute a pre-approved
* transaction as the multisig account.
*/
declare type MultisigPayload = {
multisig_address: Address;
transaction_payload?: MultisigTransactionPayload;
};
declare type TransactionPayload_MultisigPayload = ({
type: string;
} & MultisigPayload);
declare type TransactionPayload_ScriptPayload = ({
type: string;
} & ScriptPayload);
/**
* An enum of the possible transaction payloads
*/
declare type TransactionPayload$1 = (TransactionPayload_EntryFunctionPayload | TransactionPayload_ScriptPayload | TransactionPayload_ModuleBundlePayload | TransactionPayload_MultisigPayload);
/**
* A single Ed25519 signature
*/
declare type Ed25519Signature$1 = {
public_key: HexEncodedBytes;
signature: HexEncodedBytes;
};
declare type TransactionSignature_Ed25519Signature = ({
type: string;
} & Ed25519Signature$1);
declare type AccountSignature_Ed25519Signature = ({
type: string;
} & Ed25519Signature$1);
/**
* A Ed25519 multi-sig signature
*
* This allows k-of-n signing for a transaction
*/
declare type MultiEd25519Signature$1 = {
/**
* The public keys for the Ed25519 signature
*/
public_keys: Array<HexEncodedBytes>;
/**
* Signature associated with the public keys in the same order
*/
signatures: Array<HexEncodedBytes>;
/**
* The number of signatures required for a successful transaction
*/
threshold: number;
bitmap: HexEncodedBytes;
};
declare type AccountSignature_MultiEd25519Signature = ({
type: string;
} & MultiEd25519Signature$1);
/**
* Account signature scheme
*
* The account signature scheme allows you to have two types of accounts:
*
* 1. A single Ed25519 key account, one private key
* 2. A k-of-n multi-Ed25519 key account, multiple private keys, such that k-of-n must sign a transaction.
*/
declare type AccountSignature = (AccountSignature_Ed25519Signature | AccountSignature_MultiEd25519Signature);
/**
* Fee payer signature for fee payer transactions
*
* This allows you to have transactions across multiple accounts and with a fee payer
*/
declare type FeePayerSignature = {
sender: AccountSignature;
/**
* The other involved parties' addresses
*/
secondary_signer_addresses: Array<Address>;
/**
* The associated signatures, in the same order as the secondary addresses
*/
secondary_signers: Array<AccountSignature>;
fee_payer_address: Address;
fee_payer_signer: AccountSignature;
};
declare type TransactionSignature_FeePayerSignature = ({
type: string;
} & FeePayerSignature);
/**
* Multi agent signature for multi agent transactions
*
* This allows you to have transactions across multiple accounts
*/
declare type MultiAgentSignature = {
sender: AccountSignature;
/**
* The other involved parties' addresses
*/
secondary_signer_addresses: Array<Address>;
/**
* The associated signatures, in the same order as the secondary addresses
*/
secondary_signers: Array<AccountSignature>;
};
declare type TransactionSignature_MultiAgentSignature = ({
type: string;
} & MultiAgentSignature);
declare type TransactionSignature_MultiEd25519Signature = ({
type: string;
} & MultiEd25519Signature$1);
/**
* An enum representing the different transaction signatures available
*/
declare type TransactionSignature = (TransactionSignature_Ed25519Signature | TransactionSignature_MultiEd25519Signature | TransactionSignature_MultiAgentSignature | TransactionSignature_FeePayerSignature);
/**
* A transaction waiting in mempool
*/
declare type PendingTransaction = {
hash: HashValue;
sender: Address;
sequence_number: U64$1;
max_gas_amount: U64$1;
gas_unit_price: U64$1;
expiration_timestamp_secs: U64$1;
payload: TransactionPayload$1;
signature?: TransactionSignature;
};
declare type Transaction_PendingTransaction = ({
type: string;
} & PendingTransaction);
/**
* A state checkpoint transaction
*/
declare type StateCheckpointTransaction = {
version: U64$1;
hash: HashValue;
state_change_hash: HashValue;
event_root_hash: HashValue;
state_checkpoint_hash?: HashValue;
gas_used: U64$1;
/**
* Whether the transaction was successful
*/
success: boolean;
/**
* The VM status of the transaction, can tell useful information in a failure
*/
vm_status: string;
accumulator_root_hash: HashValue;
/**
* Final state of resources changed by the transaction
*/
changes: Array<WriteSetChange>;
timestamp: U64$1;
};
declare type Transaction_StateCheckpointTransaction = ({
type: string;
} & StateCheckpointTransaction);
/**
* A transaction submitted by a user to change the state of the blockchain
*/
declare type UserTransaction$1 = {
version: U64$1;
hash: HashValue;
state_change_hash: HashValue;
event_root_hash: HashValue;
state_checkpoint_hash?: HashValue;
gas_used: U64$1;
/**
* Whether the transaction was successful
*/
success: boolean;
/**
* The VM status of the transaction, can tell useful information in a failure
*/
vm_status: string;
accumulator_root_hash: HashValue;
/**
* Final state of resources changed by the transaction
*/
changes: Array<WriteSetChange>;
sender: Address;
sequence_number: U64$1;
max_gas_amount: U64$1;
gas_unit_price: U64$1;
expiration_timestamp_secs: U64$1;
payload: TransactionPayload$1;
signature?: TransactionSignature;
/**
* Events generated by the transaction
*/
events: Array<Event>;
timestamp: U64$1;
};
declare type Transaction_UserTransaction = ({
type: string;
} & UserTransaction$1);
/**
* Enum of the different types of transactions in Aptos
*/
declare type Transaction$1 = (Transaction_PendingTransaction | Transaction_UserTransaction | Transaction_GenesisTransaction | Transaction_BlockMetadataTransaction | Transaction_StateCheckpointTransaction);
/**
* A Block with or without transactions
*
* This contains the information about a transactions along with
* associated transactions if requested
*/
declare type Block = {
block_height: U64$1;
block_hash: HashValue;
block_timestamp: U64$1;
first_version: U64$1;
last_version: U64$1;
/**
* The transactions in the block in sequential order
*/
transactions?: Array<Transaction$1>;
};
declare class BlocksService {
readonly httpRequest: BaseHttpRequest;
constructor(httpRequest: BaseHttpRequest);
/**
* Get blocks by height
* This endpoint allows you to get the transactions in a block
* and the corresponding block information.
*
* Transactions are limited by max default transactions size. If not all transactions
* are present, the user will need to query for the rest of the transactions via the
* get transactions API.
*
* If the block is pruned, it will return a 410
* @param blockHeight Block height to lookup. Starts at 0
* @param withTransactions If set to true, include all transactions in the block
*
* If not provided, no transactions will be retrieved
* @returns Block
* @throws ApiError
*/
getBlockByHeight(blockHeight: number, withTransactions?: boolean): CancelablePromise<Block>;
/**
* Get blocks by version
* This endpoint allows you to get the transactions in a block
* and the corresponding block information given a version in the block.
*
* Transactions are limited by max default transactions size. If not all transactions
* are present, the user will need to query for the rest of the transactions via the
* get transactions API.
*
* If the block has been pruned, it will return a 410
* @param version Ledger version to lookup block information for.
* @param withTransactions If set to true, include all transactions in the block
*
* If not provided, no transactions will be retrieved
* @returns Block
* @throws ApiError
*/
getBlockByVersion(version: number, withTransactions?: boolean): CancelablePromise<Block>;
}
/**
* An event from a transaction with a version
*/
declare type VersionedEvent = {
version: U64$1;
guid: EventGuid;
sequence_number: U64$1;
type: MoveType;
/**
* The JSON representation of the event
*/
data: any;
};
declare class EventsService {
readonly httpRequest: BaseHttpRequest;
constructor(httpRequest: BaseHttpRequest);
/**
* Get events by creation number
* Event types are globally identifiable by an account `address` and
* monotonically increasing `creation_number`, one per event type emitted
* to the given account. This API returns events corresponding to that
* that event type.
* @param address Hex-encoded 32 byte Aptos account, with or without a `0x` prefix, for
* which events are queried. This refers to the account that events were
* emitted to, not the account hosting the move module that emits that
* event type.
* @param creationNumber Creation number corresponding to the event stream originating
* from the given account.
* @param start Starting sequence number of events.
*
* If unspecified, by default will retrieve the most recent events
* @param limit Max number of events to retrieve.
*
* If unspecified, defaults to default page size
* @returns VersionedEvent
* @throws ApiError
*/
getEventsByCreationNumber(address: Address, creationNumber: U64$1, start?: U64$1, limit?: number): CancelablePromise<Array<VersionedEvent>>;
/**
* Get events by event handle
* This API uses the given account `address`, `eventHandle`, and `fieldName`
* to build a key that can globally identify an event types. It then uses this
* key to return events emitted to the given account matching that event type.
* @param address Hex-encoded 32 byte Aptos account, with or without a `0x` prefix, for
* which events are queried. This refers to the account that events were
* emitted to, not the account hosting the move module that emits that
* event type.
* @param eventHandle Name of struct to lookup event handle e.g. `0x1::account::Account`
* @param fieldName Name of field to lookup event handle e.g. `withdraw_events`
* @param start Starting sequence number of events.
*
* If unspecified, by default will retrieve the most recent
* @param limit Max number of events to retrieve.
*
* If unspecified, defaults to default page size
* @returns VersionedEvent
* @throws ApiError
*/
getEventsByEventHandle(address: Address, eventHandle: MoveStructTag, fieldName: IdentifierWrapper, start?: U64$1, limit?: number): CancelablePromise<Array<VersionedEvent>>;
}
/**
* Representation of a successful healthcheck
*/
declare type HealthCheckSuccess = {
message: string;
};
declare enum RoleType {
VALIDATOR = "validator",
FULL_NODE = "full_node"
}
/**
* The struct holding all data returned to the client by the
* index endpoint (i.e., GET "/"). Only for responding in JSON
*/
declare type IndexResponse = {
/**
* Chain ID of the current chain
*/
chain_id: number;
epoch: U64$1;
ledger_version: U64$1;
oldest_ledger_version: U64$1;
ledger_timestamp: U64$1;
node_role: RoleType;
oldest_block_height: U64$1;
block_height: U64$1;
/**
* Git hash of the build of the API endpoint. Can be used to determine the exact
* software version used by the API endpoint.
*/
git_hash?: string;
};
declare class GeneralService {
readonly httpRequest: BaseHttpRequest;
constructor(httpRequest: BaseHttpRequest);
/**
* Show OpenAPI explorer
* Provides a UI that you can use to explore the API. You can also
* retrieve the API directly at `/spec.yaml` and `/spec.json`.
* @returns string
* @throws ApiError
*/
spec(): CancelablePromise<string>;
/**
* Check basic node health
* By default this endpoint just checks that it can get the latest ledger
* info and then returns 200.
*
* If the duration_secs param is provided, this endpoint will return a
* 200 if the following condition is true:
*
* `server_latest_ledger_info_timestamp >= server_current_time_timestamp - duration_secs`
* @param durationSecs Threshold in seconds that the server can be behind to be considered healthy
*
* If not provided, the healthcheck will always succeed
* @returns HealthCheckSuccess
* @throws ApiError
*/
healthy(durationSecs?: number): CancelablePromise<HealthCheckSuccess>;
/**
* Get ledger info
* Get the latest ledger information, including data such as chain ID,
* role type, ledger versions, epoch, etc.
* @returns IndexResponse
* @throws ApiError
*/
getLedgerInfo(): CancelablePromise<IndexResponse>;
}
/**
* A string containing a 128-bit unsigned integer.
*
* We represent u128 values as a string to ensure compatibility with languages such
* as JavaScript that do not parse u128s in JSON natively.
*
*/
declare type U128 = string;
/**
* A string containing a 256-bit unsigned integer.
*
* We represent u256 values as a string to ensure compatibility with languages such
* as JavaScript that do not parse u256s in JSON natively.
*
*/
declare type U256 = string;
/**
* An enum of the possible Move value types
*/
declare typ