Client class for the Krist API. Options may be specified as a constructor parameter.

Hierarchy

  • KristApi

Constructors

API Fetch - Names

checkNameAvailability: ((this: KristApi, name: string) => Promise<boolean>) = checkNameAvailability

Type declaration

    • (this: KristApi, name: string): Promise<boolean>
    • Checks whether a name is available to be purchased.

      See

      https://krist.dev/docs/#api-NameGroup-CheckName

      Returns

      Whether the name is available.

      Parameters

      • this: KristApi
      • name: string

        The name to check the availability of, without the .kst suffix.

      Returns Promise<boolean>

getName: ((this: KristApi, name: string) => Promise<KristName>) = getName

Type declaration

getNameBonus: ((this: KristApi) => Promise<number>) = getNameBonus

Type declaration

    • (this: KristApi): Promise<number>
    • Gets the amount of KST that is currently added to the base block reward. Essentially, this is the count of names registered in the last 500 blocks.

      Deprecated

      Block submission is currently disabled, so all new names will increase the bonus, but this does not currently mean anything.

      Returns

      The name bonus.

      Parameters

      Returns Promise<number>

getNameCost: ((this: KristApi) => Promise<number>) = getNameCost

Type declaration

    • (this: KristApi): Promise<number>
    • Deprecated

      Use motd to get API/currency constants instead.

      Parameters

      Returns Promise<number>

getNames: ((this: KristApi, options?: KristApiPaginationOptions) => Promise<NamesResponse>) = getNames

Type declaration

getNewNames: ((this: KristApi, options?: KristApiPaginationOptions) => Promise<NamesResponse>) = getNewNames

Type declaration

paginateNames: ((this: KristApi, initialOptions?: KristApiPaginationOptions, onPageFn?: OnPageFn<KristName>) => Promise<number>) = paginateNames

Type declaration

paginateNewNames: ((this: KristApi, initialOptions?: KristApiPaginationOptions, onPageFn?: OnPageFn<KristName>) => Promise<number>) = paginateNewNames

Type declaration

API Fetch - Addresses

getAddress: ((this: KristApi, address: string, fetchNames?: boolean) => Promise<KristAddress>) = getAddress

Type declaration

getAddressNames: ((this: KristApi, address: string, options?: KristApiPaginationOptions) => Promise<NamesResponse>) = getAddressNames

Type declaration

getAddressTransactions: ((this: KristApi, address: string, options?: KristApiTransactionPaginationOptions) => Promise<TransactionsResponse>) = getAddressTransactions

Type declaration

getAddresses: ((this: KristApi, options?: KristApiPaginationOptions) => Promise<AddressesResponse>) = getAddresses

Type declaration

getRichAddresses: ((this: KristApi, options?: KristApiPaginationOptions) => Promise<AddressesResponse>) = getRichAddresses

Type declaration

paginateAddressNames: ((this: KristApi, address: string, initialOptions?: KristApiPaginationOptions, onPageFn?: OnPageFn<KristName>) => Promise<number>) = paginateAddressNames

Type declaration

    • (this: KristApi, address: string, initialOptions?: KristApiPaginationOptions, onPageFn?: OnPageFn<KristName>): Promise<number>
    • Paginates the list of names owned by an address, sorted by name ascending. The callback onPageFn will be called for each page of results.

      The first argument of the callback will be the array of KristName results for that page. The second argument of the callback will be the total number of results for the query. If the callback returns false, pagination will stop.

      See

      https://krist.dev/docs/#api-AddressGroup-GetAddressNames

      Returns

      The total number of results for the query.

      Parameters

      Returns Promise<number>

paginateAddressTransactions: ((this: KristApi, address: string, initialOptions?: KristApiPaginationOptions, onPageFn?: OnPageFn<KristTransaction>) => Promise<number>) = paginateAddressTransactions

Type declaration

paginateAddresses: ((this: KristApi, initialOptions?: KristApiPaginationOptions, onPageFn?: OnPageFn<KristAddress>) => Promise<number>) = paginateAddresses

Type declaration

paginateRichAddresses: ((this: KristApi, initialOptions?: KristApiPaginationOptions, onPageFn?: OnPageFn<KristAddress>) => Promise<number>) = paginateRichAddresses

Type declaration

API Fetch - Transactions

getLatestTransactions: ((this: KristApi, options?: KristApiTransactionPaginationOptions) => Promise<TransactionsResponse>) = getLatestTransactions

Type declaration

getTransaction: ((this: KristApi, id: number) => Promise<KristTransaction>) = getTransaction

Type declaration

getTransactions: ((this: KristApi, options?: KristApiTransactionPaginationOptions) => Promise<TransactionsResponse>) = getTransactions

Type declaration

paginateLatestTransactions: ((this: KristApi, initialOptions?: KristApiTransactionPaginationOptions, onPageFn?: OnPageFn<KristTransaction>) => Promise<number>) = paginateLatestTransactions

Type declaration

paginateTransactions: ((this: KristApi, initialOptions?: KristApiTransactionPaginationOptions, onPageFn?: OnPageFn<KristTransaction>) => Promise<number>) = paginateTransactions

Type declaration

API Miscellaneous

login: ((this: KristApi, options?: KristAuthOptions) => Promise<KristLoginResponse>) = login

Type declaration

motd: ((this: KristApi) => Promise<KristMotd>) = motd

Type declaration

supply: ((this: KristApi) => Promise<number>) = supply

Type declaration

    • (this: KristApi): Promise<number>
    • Gets the money supply - the amount of Krist currently in circulation. This is calculated as the sum of all address balances, but due to historical discrepancies in the Krist database, it is not necessarily the same value as the amount of Krist ever mined.

      See

      https://krist.dev/docs/#api-MiscellaneousGroup-GetMoneySupply

      Returns

      The amount of Krist currently in circulation.

      Parameters

      Returns Promise<number>

API Submit - Transactions

makeTransaction: ((this: KristApi, to: string, amount: number, options?: KristApiMakeTransactionOptions) => Promise<KristTransaction>) = makeTransaction

Type declaration

API Submit - Names

registerName: ((this: KristApi, name: string, options?: KristAuthOptions) => Promise<KristName>) = registerName

Type declaration

transferName: ((this: KristApi, name: string, newOwner: string, options?: KristAuthOptions) => Promise<KristName>) = transferName

Type declaration

updateName: ((this: KristApi, name: string, data?: null | string, options?: KristAuthOptions) => Promise<KristName>) = updateName

Type declaration

Properties

syncNode: string
userAgent: string

Methods

  • Creates a new Krist WebSocket client with the specified options. If a password or private key are not supplied, the connection will be a "guest" connection. The WebSocket client will automatically reconnect if the connection is lost. See KristWsClient for more information.

    After calling createWsClient, you can register event listeners with ws.on(event, listener).

    After registering the event listeners, you must call ws.connect(); to begin the connection to the Krist server.

    See KristWsClient for a full list of supported events and methods.

    Example

    Connecting to the Krist API and listening for global transaction events:

    import { KristApi } from "krist";
    const api = new KristApi();

    // Create a new websocket client. Subscribe to all transaction events
    const ws = api.createWsClient({
    initialSubscriptions: ["transactions"]
    });

    // Set up the event listeners before connecting
    ws.on("transaction", transaction => {
    console.log("New transaction received:", transaction);
    });

    ws.on("ready", async () => {
    // Connected! Requests can now be made to the websocket server:
    const me = await ws.getMe();
    console.log("Websocket client now ready! I am:", me);
    });

    ws.connect(); // Connect to the websocket server

    See

    KristWsClient

    Returns

    A new KristWsClient instance.

    Parameters

    Returns KristWsClient

Advanced

  • Make a raw GET request to the Krist API. The methods for a specific API request should be used instead of this function.

    Returns

    The response of the request.

    Type Parameters

    • T

      The type of the response body when parsed as JSON.

    Parameters

    • endpoint: string

      The endpoint to request, starting with /.

    • Optional qs: any

      The query string to use for the request. May be an object or a string.

    • Optional options: RequestInit

      The fetch options to use for the request.

    Returns Promise<KristApiResponse<T>>

  • Make a raw POST request to the Krist API. The methods for a specific API request should be used instead of this function.

    Returns

    The response of the request.

    Type Parameters

    • T

      The type of the response body when parsed as JSON.

    Parameters

    • endpoint: string

      The endpoint to request, starting with /.

    • Optional body: any
    • Optional qs: any

      The query string to use for the request. May be an object or a string.

    • Optional options: RequestInit

      The fetch options to use for the request.

    Returns Promise<KristApiResponse<T>>

  • Make a raw request to the Krist API. The methods for a specific API request should be used instead of this function.

    Returns

    The response of the request.

    Type Parameters

    • T

      The type of the response body when parsed as JSON.

    Parameters

    • method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"

      The HTTP method to use for the request.

    • endpoint: string

      The endpoint to request, starting with /.

    • Optional qs: any

      The query string to use for the request. May be an object or a string.

    • Optional options: RequestInit

      The fetch options to use for the request.

    Returns Promise<KristApiResponse<T>>

Generated using TypeDoc