How to Set Up and Use Astrograph: A Step-by-Step Guide

Dec 30, 2023 | Blockchain

Astrograph is an innovative GraphQL server tailored for the Stellar network. It allows developers to efficiently query blockchain data and subscribe to events related to account activities. In this article, we’ll walk through the process of setting it up using Docker, developing applications, and utilizing its powerful features.

Getting Started: Installation with Docker

The simplest way to launch Astrograph for testing purposes is through Docker Compose. Below are the instructions to get you started:

1. Using Docker Compose

  • For the Pubnet:
    docker-compose -f docker_compose/docker-compose.pubnet.yaml up -d
    docker exec -it astrograph-stellar-core-postgres-pubnet psql -U stellar -d stellar -f init.sql
  • For the Testnet:
    docker-compose -f docker_compose/docker-compose.testnet.yaml up -d
    docker exec -it astrograph-stellar-core-postgres-testnet psql -U stellar -d stellar -f init.sql

2. Confirming Installations

Once Astrograph is set up, it automatically exports the following ports for access:

  • Astrograph GraphQL sandbox: 4000 (Pubnet), 5000 (Testnet)
  • Stellar Core HTTP ports: 11625, 11626 (Pubnet); 12625, 12626 (Testnet)
  • Elasticsearch HTTP endpoint: 9200 (Pubnet), 9300 (Testnet)

To ensure the system is running smoothly, open your browser and visit http://localhost:4000 (for pubnet) or http://localhost:5000 (for testnet). You can subscribe to new ledgers using GraphQL subscriptions:

graphql subscription ledgerCreated { seq }

Understanding the Code: An Analogous Perspective

Imagine you are an architect, and you’re designing a new building. Each component of the building represents a part of the code you are implementing. The base of your building (the database) needs to be solid to support the walls (the API). The walls must be carefully planned so that they accommodate windows and doors (the queries and subscriptions).

Here’s how that analogy plays out in the code:

  • The database connection URL (DATABASE_URL) is like the foundation you lay; it shapes everything built on top of it.
  • The port settings (PORT) represent the pathways (entrances and exits) to and from your building, allowing interaction.
  • The debugging options (DEBUG_LEDGER, DEBUG_SQL) are like blueprints that help identify mistakes in your structure.

Setting Up for Development

If you intend to develop Astrograph as a standalone JavaScript application, follow these steps:

$ git clone https://github.com/astroband/astrograph
$ cd astrograph
$ yarn                          # install dependencies
$ yarn run dev                  # for development
$ yarn run prod                 # for production setup
$ yarn ts-node src/ingestd.ts   # to live ingest subscriptions

Testing the Integration

Astrograph is equipped with Jest for testing. Execute the following to run tests:

$ yarn run test

To run unit and integration tests separately, you can use:

$ yarn run test:unit
$ yarn run test:integration

Troubleshooting Tips

If you encounter any issues during the setup or while using Astrograph, consider the following troubleshooting steps:

  • Ensure that you have Docker installed and up-to-date.
  • Check if port 4000 or 5000 are already in use by another application.
  • Review the configuration settings in your .env file to ensure they are correct.
  • Monitor logs for any error messages and address them accordingly.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Query Examples

Astrograph supports numerous queries. Here’s how to fetch information:

graphql query account(id: "GBSTRUSD7IRX73RQZBL3RQUH6KS3O4NYFY3QCALDLZD77XMZOPWAVTUK") {
  id
  inflationDestination
  balances {
    asset {
      id
      code
      issuer {
        id
      }
      balance
      limit
    }
  }
}

This will return details about a specific account, including its balances and asset information. Break down complex queries into simpler requests to avoid overloading the server.

Conclusion

Astrograph is a valuable tool for developers working with the Stellar blockchain, offering a robust GraphQL interface. By following this guide, you can set it up quickly, start developing, and effectively utilize its features. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox