package.json
file in your project directory, which will store your project’s dependencies and other information.
.env
in your root directory and add your Covalent JSON web token (JWT) in the following format:
.env
file allows you to reduce the risk of exposing secrets. Read How to store your Web3 DApp secrets: Guide to environment variables to learn more about keeping your secrets safe.index.js
and paste the following code:
ChainstackApi
class to interact with the Get transactions for address from the Covalent API using Axios.
It fetches every transaction ever made by an address on a given blockchain network, the Ethereum mainnet in this example. Here’s how the code works step by step:
ChainstackApi
class with a constructor that initializes the JWT and creates an encoded key for authentication.
COVALENT_JWT_TOKEN
to the value from the environment variable.fetchTransactions
method within the ChainstackApi
class.
chainName
, walletAddress
, currency
, and noLogs
.
You can use the noLogs
option to decide whether you want to retrieve the logs or not; depending on your need, keeping the logs off can save some resources, as logs are usually an extensive response.
main
async function that:
ChainstackApi
class.chainName
, walletAddress
, currency
, and noLogs
.fetchTransactions
method of the ChainstackApi
instance and destructures the data
property from the response, storing it in transactionsData
.transactionsData
to the console.main
function to execute the code.
ChainstackApi
class and then export it with module.exports = ChainstackApi;
.This allows you to import the ChainstackApi
class into other files and use its methods. Import it with this line, const ChainstackApi = require('./PATH_TO_YOUR_FILE')
.node
command:
transactionsData
object from the response, which includes general information and an items
object listing the details of every transaction.
Example of a response:
ChainstackApi
class.