Keeta LogoKeeta Logo@keetanetwork/keetanet-client
    Preparing search index...

    Class UserClient

    The UserClient class provides a high-level interface, user-oriented interface to the Keeta network. It is designed to be easy to use and handle the most common cases for applications building on top of the Keeta network.

      import { UserClient } from '@keetanetwork/keetanet-client';
    import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client`;
    const seed = '...'; // 64 character hex seed
    const account = KeetaNetLib.Account.fromSeed(seed, 0);
    const client = UserClient.fromNetwork('test');
    const blocks = await client.chain();
    Index

    Constructors

    • Construct a new instance of the UserClient class from the given configuration. This will use the default representatives for the network based on the configuration.

      New instances should be cleaned up with the destroy method when they are no longer needed.

      The recommended way to create a new instance of the UserClient class is to use the fromNetwork method.

      Parameters

      Returns UserClient

    Properties

    baseToken: TokenAddress

    The base token for the network this client is connected to.

    networkAddress: NetworkAddress

    The network address for the network this client is connected to.

    Config: src/config = Config

    Reference to the Config class for the client. This is used to access the Configuration operations which may be needed for the UserClient.

    isInstance: (obj: any, strict?: boolean) => obj is UserClient = ...

    Determine if a given object is an instance of the UserClient class. This is preferred over using instanceof because it works across different contexts.

    Accessors

    • get account(): GenericAccount

      Get the account for this instance. This is the account that will be affected by the blocks and transactions that are published.

      Returns GenericAccount

    • get network(): bigint

      Get the network ID for this instance. This is the network that this instance is connected to.

      Returns bigint

    • get readonly(): boolean

      Whether or not this client is "readonly". This is true if the signer is null.

      Returns boolean

    Methods

    • Get the balance for a given token for the given account. See Client.getBalance for more information.

      Parameters

      Returns Promise<bigint>

      The balance for the account of the given token

    • Get a specific block by its hash. This will return the block if it is known to the network or null if it is not.

      Parameters

      • blockhash: string | BlockHash

        The hash of the block to get

      Returns Promise<null | Block>

      The block if it is known to the network or null if it is not

    • Get the chain for the given account. This will return the chain as Client.getChain does.

      Parameters

      • Optionalquery: { depth?: number; startBlock?: string | BlockHash }

        The query to use for the chain

      • options: UserClientOptionsReadOnly = {}

        The options to use for the request

      Returns Promise<Block[]>

      The chain for the account, paginated

    • Destroy this instance -- this is required to clean up all resources.

      Returns Promise<void>

    • Filter the given vote staples for the user client account. See UserClient.filterStapleOperations for more information.

      Parameters

      Returns {
          [stapleHash: string]: {
              block: Block;
              filteredOperations: BlockOperations[];
          }[];
      }

      The filtered operations for the given account, ordered by vote staple hash, then by block, and then containing each operation

    • Get the current head block for the given account. This will return the hash of the current head block for the account or null if the account has no blocks.

      Parameters

      Returns Promise<null | BlockHash>

      The hash of the current head block for the account or null if the account has no blocks

    • Generate and publish the blocks needed to initialize a new network with the given parameters.

      This is generally only needed once per network and is used to initialize the network with a base token and a representative in order to start-up the network.

      Parameters

      • initOpts: {
            addSupplyAmount: bigint;
            delegateTo?: Account<ECDSA_SECP256K1 | ED25519 | ECDSA_SECP256R1>;
            voteSerial?: bigint;
        }

        The options to use for the initialization

        • addSupplyAmount: bigint

          The amount of supply to add to the network of the base token

        • OptionaldelegateTo?: Account<ECDSA_SECP256K1 | ED25519 | ECDSA_SECP256R1>

          The representative account to delegate the supply to

        • OptionalvoteSerial?: bigint

          The serial number to use for the vote -- must never be reused by the representative

      • options: UserClientOptions = {}

        The options to use for the request

      Returns Promise<{ from: "direct"; publish: boolean; voteStaple: VoteStaple }>

      The vote staple that was generated and whether it was able to be published

    • Modify both the token supply (mint/burn) and account balance for a given account of a given token.

      This will mint if a positive amount is given and burn if a negative amount is given, and the add or subtract the same amount from the account balance.

      Parameters

      • amount: bigint

        The amount to add or subtract from the token supply and account balance

      • token: TokenAddress

        The token to modify the supply and balance for

      • options: UserClientOptionsReadOnly = {}

        The options to use for the request

      Returns Promise<
          | { from: "direct"; publish: boolean; voteStaple: VoteStaple }
          | { blocks: Block[]; from: "publish-aid"; publish: boolean },
      >

      The vote staple that was generated and whether it was able to be published

    • Cancel a previously registered callback from on

      Parameters

      • id: symbol

      Returns void

    • Register a callback for change messages and set up a websocket filtered to our account only. Also set up long timeout polling for changes in case the websocket misses a change update Check that parameters of function complies with respective event function

      Type Parameters

      • EventName extends "change"

      Parameters

      Returns symbol

    • Get the pending block for the given account. This will return any side-ledger block for that account, or null if there is no pending block.

      Parameters

      Returns Promise<null | Block>

      The pending block for the account or null if there is no pending block

    • Compute the blocks needed to publish a given builder and then publish those blocks to the network. The builder should generally not be used after this method is called as the blocks will be published and the builder will be in an invalid state.

      In general, the UserClientBuilder.publish method should be used instead of this one.

      Parameters

      Returns Promise<
          | { from: "direct"; publish: boolean; voteStaple: VoteStaple }
          | { blocks: Block[]; from: "publish-aid"; publish: boolean },
      >

      The vote staple that was generated and whether it was able to be published

    • Recover any unpublished or half-publish account artifacts

      Parameters

      • Optionalpublish: boolean

        Publish the recovered staple to the network (default: true)

      • options: UserClientOptions = {}

        User client options (common options)

      Returns Promise<null | VoteStaple>

    • Send some tokens from this account to another account.

      If an external identifier is provided, it will be included in the Send operation and can be used by the recipient to identify the transaction.

      Parameters

      • to: string | GenericAccount

        The account to send the tokens to

      • amount: number | bigint

        The amount of tokens to send (in base units)

      • token: string | TokenAddress

        The token to send

      • Optionalexternal: string

        The external identifier to use for the transaction

      • options: UserClientOptions = {}

        The options to use for the request

      • retries: number = 0

        The number of times to retry the request if it fails

      Returns Promise<void>

      The vote staple that was generated and whether it was able to be published

    • Set the metadata for an account and publish the blocks to the network.

      Parameters

      Returns Promise<
          | { from: "direct"; publish: boolean; voteStaple: VoteStaple }
          | { blocks: Block[]; from: "publish-aid"; publish: boolean },
      >

      The vote staple that was generated and whether it was able to be published

    • Update the permissions for a given account. This will publish the changes to the network.

      Parameters

      • principal: string | GenericAccount

        The account to update the permissions regarding for this account

      • permissions: AcceptedPermissionTypes

        The permissions to set for the account

      • Optionaltarget: string | GenericAccount

        The account to set the permissions for, if applicable for this permission

      • Optionalmethod: AdjustMethod

        The method to use for the permission, defaults to SET

      • options: UserClientOptions = {}

        The options to use for the request

      Returns Promise<
          | { from: "direct"; publish: boolean; voteStaple: VoteStaple }
          | { blocks: Block[]; from: "publish-aid"; publish: boolean },
      >

      The vote staple that was generated and whether it was able to be published

    • Helper method to filter a list of vote staples into a list of blocks and operations that are related to a given account.

      Parameters

      • voteStaples: VoteStaple[]

        The list of vote staples to filter

      • account: GenericAccount

        The account to search for operations related to

      Returns {
          [stapleHash: string]: {
              block: Block;
              filteredOperations: BlockOperations[];
          }[];
      }

      An array of filtered operations for the given account, ordered by vote staple hash, then by block, and then containing each operation

    • Construct a new instance of the UserClient class from the given network name. This will use the default representatives for the network based on the configuration.

      New instances should be cleaned up with the destroy() method when they are no longer needed.

      This is the recommended way to create a new instance of the UserClient class.

      Parameters

      • network: "production" | "staging" | "beta" | "test" | "dev"

        The network to use for this instance of the UserClient class

      • signer: null | Account<ECDSA_SECP256K1 | ED25519 | ECDSA_SECP256R1>

        The account to use for this instance of the UserClient class, or null if this is a read-only client

      • Optionaloptions: UserClientOptions

        The options to use for this instance of the UserClient class

        • Optionalaccount?: GenericAccount

          The account to use for the user client, if this is not supplied then the signer will be used (if available) otherwise this there will be no account and some operations may not be available.

        • OptionalpublishAidURL?: string

          If using the publish aid (see ['usePublishAid']) the URL to use.

          The default depends on the network configuration.

        • OptionalusePublishAid?: boolean

          Use the "publish aid" service to publish blocks.

          This service handles requesting short votes and permanent votes and publishing to the network. This can reduce latency for clients far away from representatives because they only need to wait for a single response instead of multiple round-trips.

          The default is false.

      Returns UserClient

      A new instance of the UserClient class

    • A helper method to get the configuration from the network alias and options. This will use the default representatives for the network based on the configuration.

      Parameters

      • network: "production" | "staging" | "beta" | "test" | "dev"

        The network to use to generate the configuration

      • Optionaloptions: UserClientOptions

        The options to use to generate the configuration

      Returns Omit<UserClientConfig, "signer">

      The configuration object for the UserClient class