'What is the 16 in (chainId, 16) in an Eth smart contract that is on the Rinkeby network

I am new to smart contracts and I am working on an Eth Rinkeby dapp and was wondering if anyone can tell me what the "16" means in this section:

}

    network = await getChain(parseInt(chainId, 16));
    this.setState({
      network: network.network,
      loading: false,
      onlyNetwork: false,
    });
  });
}

I know what chainID is but 16 doesn't belong to the Rinkeby network from what I can tell.

Any help is greatly appreciated.

Thank you!



Solution 1:[1]

Ken White's comment is correct.

parseInt is a built-in JavaScript function. The first parameter is the number. In the case of Rinkeby, this chainId is 4 (4 in hexadecimal). The second parameter is the base. For hexadecimal, this is 16.

As it happens, the decimal and hexadecimal numbers are the same. But, for example, if you were using the xDAI mainnet, the chainId in decimal is 100, but in hexadecimal (which is what chain IDs are usually represented in), it's 64.

parseInt needs to know the base in order to correctly convert the string containing the chain ID to the correct number. If the chainId string starts with 0x (e.g. 0x64), then parseInt can correctly tell what the base is (16). However, this is not always the case, so 16 is manually passed in to ensure that the correct base is used.

Documentation: https://www.w3schools.com/jsref/jsref_parseint.asp

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pandapip1