Set Up the Development Environment

Before exploring the various features of the Blockdaemon DeFi API, we need to set up our development environment with some example scripts. The following guides use the typescript SDK and a generic REST API.

We assume basic knowledge of node.js and your operating systemโ€™s command line interface.

Before we delve into the code, letโ€™s set some groundwork:

  1. Contact us to get the API key, or go to https://app.blockdaemon.com/.
  2. Clone our DeFi API example project: git clone https://github.com/Blockdaemon/defi-api-examples.git
  3. Enter into the project directory: cd defi-api-examples.
  4. Follow the setup instructions in the project README. The README.md explores a set of functionalities such as obtaining chain information, token information, and conducting a swap. Please refer to the accompanying guides for more details.

All scripts in the DeFi API example project rely on shared code. For the complete code, please refer to https://github.com/Blockdaemon/defi-api-examples.

The standard initialisation code reads and validates the entries in your .env file and exports a few useful objects:

  • logger is an instance of a https://github.com/log4js-node/log4js-node logger for consistent logging throughout the example scripts.
  • apiConfig is an instance of the configuration object required by the DeFi API typescript SDK. It contains the API endpoint as well as the API key from your .env file.
  • optimismWallet and polygonWallet can be used to sign and broadcast transactions using either the web3js library or the ethers library, and the Blockdaemon RPC API.

๐Ÿ‘‹ Need Help?

Contact us through email or our support page for any issues, bugs, or assistance you may need.