Installation

Import the Library in Your Project

Installation

  • Install Node.js and Yarn, if you haven't already.

  • Create a new directory for your project.

  • Inside your project directory, run the following command to initialize a new npm project:

yarn init -y
  • Install XChainJS and any necessary dependencies. You can install XChainJS via npm/yarn:

yarn add @xchainjs/xchain-bitcoin

For example, yarn add @xchainjs/xchain-thorchain

node server.js

Dependencies & Peer Dependencies

When you develop a package that depends on other packages (dependencies), you typically specify these dependencies in your package.json file. There are two types of dependencies: dependencies and peerDependencies.

Dependencies

These are packages that your module requires to function correctly. When someone installs your package using npm or yarn, these dependencies are automatically installed as well.

Peer Dependencies

When you install a software package like "xchain-lib," which is used for blockchain projects, it requires that you have certain other packages already installed. These required packages are known as peer dependencies. Unlike regular dependencies, peer dependencies are not automatically installed alongside "xchain-lib." You need to install them separately.

This approach is chosen for a few key reasons:

  • Compatibility: "xchain-lib" might depend on specific versions of its peer dependencies to ensure everything works together smoothly. Requiring you to install them separately allows for greater flexibility in managing compatible versions.

  • Reduced Package Size: Not including these dependencies in "xchain-lib" keeps its size smaller. This way, you only install what's necessary for your project, avoiding unnecessary bloat.

  • Version Control: Since peer dependencies are not automatically updated, you maintain control over which versions are used in your project. This can help avoid issues that arise from incompatible updates.

  • Avoiding Duplication: If multiple packages use the same dependencies, having them as peer dependencies means they can share a single installation of that dependency. This reduces duplication and potential conflicts within your project setup.

In summary, managing peer dependencies separately offers benefits in terms of compatibility, package size, version control, and avoiding duplication, though it requires a bit more effort upfront to set up your project environment.

How to Find & Use Peer Dependencies Correctly

To find the correct Peer Dependencies of your desired xchain package you can visit the 'xchain-lib/package' in the repository to get the updated peer dependencies by looking at the "peerDependencies" object in the "package.json" file.

For example, if you want to find & use the Peer Dependencies of the xchain-bitcoin package then you can look at the "peerDependencies" object in the "package.json" file of the xchain-bitcoin package.

Last updated