Interface Hacknet

Hacknet API

Remarks

Not all these functions are immediately available.

interface Hacknet {
    getCacheUpgradeCost(index, n?): number;
    getCoreUpgradeCost(index, n?): number;
    getHashUpgradeLevel(upgName): number;
    getHashUpgrades(): string[];
    getLevelUpgradeCost(index, n?): number;
    getNodeStats(index): NodeStats;
    getPurchaseNodeCost(): number;
    getRamUpgradeCost(index, n?): number;
    getStudyMult(): number;
    getTrainingMult(): number;
    hashCapacity(): number;
    hashCost(upgName, count?): number;
    maxNumNodes(): number;
    numHashes(): number;
    numNodes(): number;
    purchaseNode(): number;
    spendHashes(upgName, upgTarget?, count?): boolean;
    upgradeCache(index, n?): boolean;
    upgradeCore(index, n?): boolean;
    upgradeLevel(index, n?): boolean;
    upgradeRam(index, n?): boolean;
}

Methods

  • Calculate the cost of upgrading hacknet node cache.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node.

    • Optional n: number

      Number of times to upgrade cache. Must be positive. Will be rounded to the nearest integer. Defaults to 1 if not specified.

    Returns number

    Cost of upgrading the specified Hacknet Node's cache.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

    Returns the cost of upgrading the cache level of the specified Hacknet Server by n.

    If an invalid value for n is provided, then this function returns 0. If the specified Hacknet Node is already at max level, then Infinity is returned.

  • Calculate the cost of upgrading hacknet node cores.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node.

    • Optional n: number

      Number of times to upgrade cores. Must be positive. Will be rounded to the nearest integer. Defaults to 1 if not specified.

    Returns number

    Cost of upgrading the specified Hacknet Node's number of cores.

    Remarks

    RAM cost: 0 GB

    Returns the cost of upgrading the number of cores of the specified Hacknet Node by n.

    If an invalid value for n is provided, then this function returns 0. If the specified Hacknet Node is already at max level, then Infinity is returned.

  • Get the level of a hash upgrade.

    Parameters

    • upgName: string

    Returns number

    Level of the upgrade.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

  • Get the list of hash upgrades

    Returns string[]

    An array containing the available upgrades

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

    Returns the list of all available hash upgrades that can be used in the spendHashes function.

    Example

    const upgrades = ns.hacknet.getHashUpgrades(); // ["Sell for Money","Sell for Corporation Funds",...]
    
  • Calculate the cost of upgrading hacknet node levels.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node.

    • Optional n: number

      Number of levels to upgrade. Must be positive. Will be rounded to the nearest integer. Defaults to 1 if not specified.

    Returns number

    Cost of upgrading the specified Hacknet Node.

    Remarks

    RAM cost: 0 GB

    Returns the cost of upgrading the specified Hacknet Node by n levels.

    If an invalid value for n is provided, then this function returns 0. If the specified Hacknet Node is already at max level, then Infinity is returned.

  • Get the stats of a hacknet node.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node

    Returns NodeStats

    Object containing a variety of stats about the specified Hacknet Node.

    Remarks

    RAM cost: 0 GB

    Returns an object containing a variety of stats about the specified Hacknet Node.

    Note that for Hacknet Nodes, production refers to the amount of money the node generates. For Hacknet Servers (the upgraded version of Hacknet Nodes), production refers to the amount of hashes the node generates.

  • Get the price of the next hacknet node.

    Returns number

    Cost of purchasing a new Hacknet Node.

    Remarks

    RAM cost: 0 GB

    Returns the cost of purchasing a new Hacknet Node.

  • Calculate the cost of upgrading hacknet node RAM.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node.

    • Optional n: number

      Number of times to upgrade RAM. Must be positive. Will be rounded to the nearest integer. Defaults to 1 if not specified.

    Returns number

    Cost of upgrading the specified Hacknet Node's RAM.

    Remarks

    RAM cost: 0 GB

    Returns the cost of upgrading the RAM of the specified Hacknet Node n times.

    If an invalid value for n is provided, then this function returns 0. If the specified Hacknet Node already has max RAM, then Infinity is returned.

  • Get the multiplier to study.

    Returns number

    Multiplier.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

  • Get the multiplier to training.

    Returns number

    Multiplier.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

  • Get the maximum number of hashes you can store.

    Returns number

    Number of hashes you can store.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

    Returns the number of hashes you can store.

  • Get the cost of a hash upgrade.

    Parameters

    • upgName: string

      Name of the upgrade of Hacknet Node.

    • Optional count: number

      Number of upgrades to buy at once. Defaults to 1 if not specified.

    Returns number

    Number of hashes required for the specified upgrade.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

    Returns the number of hashes required for the specified upgrade. The name of the upgrade must be an exact match.

    Example

    const upgradeName = "Sell for Corporation Funds";
    if (ns.hacknet.numHashes() > ns.hacknet.hashCost(upgradeName)) {
    ns.hacknet.spendHashes(upgradeName);
    }
  • Get the maximum number of hacknet nodes.

    Returns number

    Maximum number of hacknet nodes.

    Remarks

    RAM cost: 0 GB

  • Get the total number of hashes stored.

    Returns number

    Number of hashes you have.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

    Returns the number of hashes you have.

  • Get the number of hacknet nodes you own.

    Returns number

    Number of hacknet nodes.

    Remarks

    RAM cost: 0 GB

    Returns the number of Hacknet Nodes you own.

  • Purchase a new hacknet node.

    Returns number

    The index of the Hacknet Node or if the player cannot afford to purchase a new Hacknet Node the function will return -1.

    Remarks

    RAM cost: 0 GB

    Purchases a new Hacknet Node. Returns a number with the index of the Hacknet Node. This index is equivalent to the number at the end of the Hacknet Node’s name (e.g. The Hacknet Node named hacknet-node-4 will have an index of 4).

    If the player cannot afford to purchase a new Hacknet Node then the function will return -1.

  • Purchase a hash upgrade.

    Parameters

    • upgName: string

      Name of the upgrade of Hacknet Node.

    • Optional upgTarget: string

      Object to which upgrade applies. Required for certain upgrades.

    • Optional count: number

      Number of upgrades to buy at once. Defaults to 1 if not specified. For compatibility reasons, upgTarget must be specified, even if it is not used, in order to specify count.

    Returns boolean

    True if the upgrade is successfully purchased, and false otherwise.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

    Spend the hashes generated by your Hacknet Servers on an upgrade. Returns a boolean value - true if the upgrade is successfully purchased, and false otherwise.

    The name of the upgrade must be an exact match. The upgTarget argument is used for upgrades such as Reduce Minimum Security, which applies to a specific server. In this case, the upgTarget argument must be the hostname of the server.

    Example

    // For upgrades where no target is required
    ns.hacknet.spendHashes("Sell for Corporation Funds");
    // For upgrades requiring a target
    ns.hacknet.spendHashes("Increase Maximum Money", "foodnstuff");
  • Upgrade the cache of a hacknet node.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node.

    • Optional n: number

      Number of cache levels to purchase. Must be positive. Will be rounded to the nearest integer. Defaults to 1 if not specified.

    Returns boolean

    True if the Hacknet Node’s cache level is successfully upgraded, false otherwise.

    Remarks

    RAM cost: 0 GB

    This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).

    Tries to upgrade the specified Hacknet Server’s cache n times.

    Returns true if it successfully upgrades the Server’s cache n times, or if it purchases some positive amount and the Server reaches its max cache level.

    Returns false otherwise.

  • Upgrade the core of a hacknet node.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node.

    • Optional n: number

      Number of cores to purchase. Must be positive. Will be rounded to the nearest integer. Defaults to 1 if not specified.

    Returns boolean

    True if the Hacknet Node’s cores are successfully purchased, false otherwise.

    Remarks

    RAM cost: 0 GB

    Tries to purchase n cores for the specified Hacknet Node.

    Returns true if it successfully purchases n cores for the Hacknet Node or if it purchases some positive amount and the Node reaches its max number of cores.

    Returns false otherwise.

  • Upgrade the level of a hacknet node.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node.

    • Optional n: number

      Number of levels to purchase. Must be positive. Will be rounded to the nearest integer. Defaults to 1 if not specified.

    Returns boolean

    True if the Hacknet Node’s level is successfully upgraded, false otherwise.

    Remarks

    RAM cost: 0 GB

    Tries to upgrade the level of the specified Hacknet Node by n.

    Returns true if the Hacknet Node’s level is successfully upgraded by n or if it is upgraded by some positive amount and the Node reaches its max level.

    Returns false otherwise.

  • Upgrade the RAM of a hacknet node.

    Parameters

    • index: number

      Index/Identifier of Hacknet Node.

    • Optional n: number

      Number of times to upgrade RAM. Must be positive. Will be rounded to the nearest integer. Defaults to 1 if not specified.

    Returns boolean

    True if the Hacknet Node’s RAM is successfully upgraded, false otherwise.

    Remarks

    RAM cost: 0 GB

    Tries to upgrade the specified Hacknet Node’s RAM n times. Note that each upgrade doubles the Node’s RAM. So this is equivalent to multiplying the Node’s RAM by 2 n.

    Returns true if the Hacknet Node’s RAM is successfully upgraded n times or if it is upgraded some positive number of times and the Node reaches its max RAM.

    Returns false otherwise.