@aptos-labs/ts-sdk
Version:
Aptos TypeScript SDK
167 lines • 10.3 kB
TypeScript
import { TypeTag } from "../typeTag/index.js";
import { AptosConfig } from "../../api/aptosConfig.js";
import { EntryFunctionArgumentTypes, SimpleEntryFunctionArgumentTypes, EntryFunctionABI, ViewFunctionABI, FunctionABI, TypeArgument } from "../types.js";
import { MoveFunction, MoveModule } from "../../types/index.js";
/**
* Convert type arguments to only type tags, allowing for string representations of type tags.
*
* @param typeArguments - An optional array of type arguments that may include string representations.
* @returns An array of TypeTag objects derived from the provided type arguments.
* @group Implementation
* @category Transactions
*/
export declare function standardizeTypeTags(typeArguments?: Array<TypeArgument>): Array<TypeTag>;
/**
* Represents a bundle of a module ABI along with all struct ABIs it references.
* This allows for offline struct/enum encoding without additional network calls.
*/
export type ModuleAbiBundle = {
/** The main module ABI */
module: MoveModule;
/** Map of modules containing referenced struct ABIs: "address::module" -> MoveModule */
referencedStructModules: Map<string, MoveModule>;
};
/**
* Fetches the ABI of a specified module from the on-chain module ABI.
* Results are cached for 5 minutes to reduce redundant network calls.
*
* @param moduleAddress - The address of the module from which to fetch the ABI.
* @param moduleName - The name of the module containing the ABI.
* @param aptosConfig - The configuration settings for Aptos.
* @group Implementation
* @category Transactions
*/
export declare function fetchModuleAbi(moduleAddress: string, moduleName: string, aptosConfig: AptosConfig): Promise<MoveModule | undefined>;
/**
* Fetches a module ABI along with all struct ABIs it references.
* This optimization minimizes nested network calls when encoding struct/enum arguments.
*
* Strategy:
* - Fetches the main module ABI
* - Parses all type references in struct fields and function parameters
* - Fetches ABIs for all referenced struct modules in parallel
* - Caches the complete bundle together
*
* @param moduleAddress - The address of the module from which to fetch the ABI.
* @param moduleName - The name of the module containing the ABI.
* @param aptosConfig - The configuration settings for Aptos.
* @returns ModuleAbiBundle containing the module and all referenced struct modules
* @group Implementation
* @category Transactions
*/
export declare function fetchModuleAbiWithStructs(moduleAddress: string, moduleName: string, aptosConfig: AptosConfig): Promise<ModuleAbiBundle>;
/**
* Fetches the ABI of a specified function from the on-chain module ABI. This function allows you to access the details of a
* specific function within a module.
*
* @param moduleAddress - The address of the module from which to fetch the function ABI.
* @param moduleName - The name of the module containing the function.
* @param functionName - The name of the function whose ABI is to be fetched.
* @param aptosConfig - The configuration settings for Aptos.
* @group Implementation
* @category Transactions
*/
export declare function fetchFunctionAbi(moduleAddress: string, moduleName: string, functionName: string, aptosConfig: AptosConfig): Promise<MoveFunction | undefined>;
/**
* @deprecated Use `fetchFunctionAbi` instead and manually parse the type tags.
*/
export declare function fetchMoveFunctionAbi(moduleAddress: string, moduleName: string, functionName: string, aptosConfig: AptosConfig): Promise<FunctionABI>;
/**
* Fetches the ABI for an entry function from the specified module address.
* This function validates if the ABI corresponds to an entry function and retrieves its parameters.
*
* @param moduleAddress - The address of the module containing the entry function.
* @param moduleName - The name of the module containing the entry function.
* @param functionName - The name of the entry function to fetch the ABI for.
* @param aptosConfig - The configuration settings for Aptos.
* @returns An object containing the number of signers, type parameters, and function parameters.
* @throws Error if the ABI cannot be found or if the function is not an entry function.
* @group Implementation
* @category Transactions
*/
export declare function fetchEntryFunctionAbi(moduleAddress: string, moduleName: string, functionName: string, aptosConfig: AptosConfig): Promise<EntryFunctionABI>;
/**
* Fetches the ABI for a view function from the specified module address.
* This function ensures that the ABI is valid and retrieves the type parameters, parameters, and return types for the view function.
*
* @param moduleAddress - The address of the module containing the view function.
* @param moduleName - The name of the module containing the view function.
* @param functionName - The name of the view function for which to fetch the ABI.
* @param aptosConfig - The configuration settings for Aptos.
* @returns An object containing the type parameters, parameters, and return types of the view function.
* @throws Error if the ABI cannot be found or if the function is not a view function.
* @group Implementation
* @category Transactions
*/
export declare function fetchViewFunctionAbi(moduleAddress: string, moduleName: string, functionName: string, aptosConfig: AptosConfig): Promise<ViewFunctionABI>;
/**
* Converts a non-BCS encoded argument into BCS encoded, if necessary.
* This is the synchronous version that works offline with pre-fetched ABIs.
* Does NOT support struct/enum arguments - use convertArgumentWithABI for those.
*
* @param functionName - The name of the function for which the argument is being converted.
* @param functionAbiOrModuleAbi - The ABI (Application Binary Interface) of the function, which defines its parameters.
* @param arg - The argument to be converted, which can be of various types.
* @param position - The index of the argument in the function's parameter list.
* @param genericTypeParams - An array of type tags for any generic type parameters.
* @param options - Options for the conversion process.
* @param options.allowUnknownStructs - If true, unknown structs will be allowed and converted to a `FixedBytes`.
* @group Implementation
* @category Transactions
*/
export declare function convertArgument(functionName: string, functionAbiOrModuleAbi: MoveModule | FunctionABI, arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes, position: number, genericTypeParams: Array<TypeTag>, options?: {
allowUnknownStructs?: boolean;
}): EntryFunctionArgumentTypes;
/**
* Converts a non-BCS encoded argument into BCS encoded, with support for struct/enum arguments.
* This is the asynchronous version that fetches module ABIs from the network as needed.
*
* @param functionName - The name of the function for which the argument is being converted.
* @param functionAbiOrModuleAbi - The ABI (Application Binary Interface) of the function, which defines its parameters.
* @param arg - The argument to be converted, which can be of various types.
* @param position - The index of the argument in the function's parameter list.
* @param genericTypeParams - An array of type tags for any generic type parameters.
* @param aptosConfig - Aptos configuration for fetching module ABIs (required for struct/enum arguments).
* @param options - Options for the conversion process.
* @param options.allowUnknownStructs - If true, unknown structs will be allowed and converted to a `FixedBytes`.
* @group Implementation
* @category Transactions
*/
export declare function convertArgumentWithABI(functionName: string, functionAbiOrModuleAbi: MoveModule | FunctionABI, arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes, position: number, genericTypeParams: Array<TypeTag>, aptosConfig: AptosConfig, options?: {
allowUnknownStructs?: boolean;
}): Promise<EntryFunctionArgumentTypes>;
/**
* Checks if the provided argument is BCS encoded and converts it if necessary, ensuring type compatibility with the ABI.
* This is the synchronous version that works offline with pre-fetched ABIs.
* Does NOT support struct/enum arguments - use checkOrConvertArgumentWithABI for those.
*
* @param arg - The argument to check or convert, which can be either a simple or entry function argument type.
* @param param - The expected type tag for the argument.
* @param position - The position of the argument in the function call.
* @param genericTypeParams - An array of generic type parameters that may be used for conversion.
* @param moduleAbi - The ABI of the module containing the function, used for type checking.
* @param options - Options for the conversion process.
* @group Implementation
* @category Transactions
*/
export declare function checkOrConvertArgument(arg: SimpleEntryFunctionArgumentTypes | EntryFunctionArgumentTypes, param: TypeTag, position: number, genericTypeParams: Array<TypeTag>, moduleAbi?: MoveModule, options?: {
allowUnknownStructs?: boolean;
}): EntryFunctionArgumentTypes;
/**
* Checks if the provided argument is BCS encoded and converts it if necessary, with support for struct/enum arguments.
* This is the asynchronous version that fetches module ABIs from the network as needed.
*
* @param arg - The argument to check or convert, which can be either a simple or entry function argument type.
* @param param - The expected type tag for the argument.
* @param position - The position of the argument in the function call.
* @param genericTypeParams - An array of generic type parameters that may be used for conversion.
* @param aptosConfig - Aptos configuration for fetching module ABIs (required for struct/enum arguments).
* @param moduleAbi - The ABI of the module containing the function, used for type checking.
* @param options - Options for the conversion process.
* @group Implementation
* @category Transactions
*/
export declare function checkOrConvertArgumentWithABI(arg: SimpleEntryFunctionArgumentTypes | EntryFunctionArgumentTypes, param: TypeTag, position: number, genericTypeParams: Array<TypeTag>, aptosConfig: AptosConfig, moduleAbi?: MoveModule, options?: {
allowUnknownStructs?: boolean;
}): Promise<EntryFunctionArgumentTypes>;
//# sourceMappingURL=remoteAbi.d.ts.map