Your interest in learning how to create your stellar horizon server implies that you want to access the Stellar network. Maybe you are building an application on the stellar network that can view transaction data, submit transactions, check the status of accounts, or subscribe to event streams. It is good that you are considering building an app on stellar. Here, quickly defining why you must go for it.
Why build an app on the Stellar network?
Businesses worldwide are overwhelmed by how Stellar as an open network is transforming the world of finance by enabling businesses, payments systems, banks, and people to integrate for reliable money transactions at a low cost. Stellar makes money borderless by facilitating fast, transparent cross-border transactions between any pair of currencies without involving any third intermediary. It is the ideal platform to improve currency connections, where even a small business has the power to reach out to an international bank.
The stellar network facilitates creating, sending, and trading digital representations of all forms of money -dollars, bitcoin, pesos, euros and much more, but stellar doesn’t privilege any particular currency. It sets up a 1:1 relationship between a digital token and a traditional currency. An equivalent fiat deposit backs every token in Stellar network. It is a powerful, better and borderless network for businesses to store and move money, especially for cross-border transactions.
A brief about Stellar Horizon and its importance in Stellar ecosystem
Stellar offer high-end API and SDKs that enable developers to build token, wallets or apps such as global payment apps, exchange assets and a range of micropayment services. Now, whether you are developing projects like wallets, decentralized exchanges, asset issuers or other apps, you require Stellar Horizon client-server for your app to interact with Stellar Core( blockchain node server), So, the Horizon is like a bridge that connects your app to the Stellar blockchain or network. After setting this connection only, you will be able to perform activities like submitting transactions, streaming transactions to an account or querying an account balance. So let’s learn how to set up a Stellar Horizon server on AWS.
How to set up Stellar Horizon Server on AWS?
Step 1: Create an EC2 instance on AWS
You can use Amazon’s Linux AMI to create an EC2 instance. While some suggest that a quite powerful instance is needed, but you can try creating an EC2 T2 instance with t2.micro. You will need to add 20G of storage space and ensure port 8000 is open in your security group and use port 22 for your ssh access.
Step 2: Assign the server hostname
A hostname is a form of the private, internal IPv4 address that looks something like this: IP-12-34-56-78.us-west-. To set up a server hostname for amazon Linux instance, run.
sudo hostnamectl set-hostname webserver.mydomain.com
After that, check that your hostname is set by running the “hostname” cmd inside the terminal.
Step 3: Setup Docker on the server
Probably you already know how to do it, yet here is a quick summary of the key steps
- Use the public DNS and the public key
- Connect to the server via SSH
- To install Docker, use yum configuration manager
sudo yum update -y
sudo yum install -y docker
- Start the docker service
sudo service docker start
- Now, to use the docker command without root privileges, add ec2-user to the docker group
sudo usermod -aG docker ec2-us
- Log out of the instance, and ssh back in for changes to take effect.
- Verify that Docker is correctly installed; once you ssh back in
Step 4: Install the Stellar Quickstart Docker Image
- To get the quickstart image running, run the command:
- docker run -it –rm -v “/str:/opt/stellar” –name stellar stellar/quickstart –pubnet
- This will fetch the GitHub repo image and you will be prompted to provide a password for the Postgres database.
- Once the Stellar Quickstart Docker Image installation completes, you will see that your horizon server has “entered the running state.”
- You can exit the running process with Control-C.
Enable the Docker Image to run as a background process
At this step, Docker Image must run as a persistent background container. This is needed so that you can log out and then allow the Horizon server to run on the instance. To do this run the command:
docker run -d -v “/str:/opt/stellar” -p “8000:8000” –name stellar stellar/quickstart –pubnet
Now, login back to the docker image running. You will see your services are with the following two commands:
docker exec -it stellar /bin/bash
With this, now your Stellar Horizon server is running. Now, Open the URL – dynamic public address of your AWS instance:8000. For example, if the name is “ec2–5–4–3–2.ap-southeast-1.compute.amazonaws.com,” then, URL would be “ec2–5–4–3–2.ap-southeast-1.compute.amazonaws.com:8000”. Here, you will see in the JSON output from your Horizon serve. Note that you may see the ‘ledger history’ output as 0 because it takes time for the ledger to update. If you are not from a technical background, consider hiring Stellar developers who have worked on Stellar blockchain projects.