Background

I was looking to stand up my own standalone Stellar network as part of a research effort. I was able to find an existing project from a SatoshiPay GitHub repo that included a Docker Compose file to become part of the Stellar live network. I thought it would be cool to see how this could be applied to the Stellar testnet and eventually be extended to Stellar standalone deployments sometime in the future.

Joining the test network

As mentioned in the background, the initial Docker Compose configuration pointed to the live network which is not what I wanted to use for this proof of concept. I did some googling and found Stellar core documents the test network configuration. I am including the contents here for ease of use.

All I had to do next was to figure out how to map these settings to compose so that my local nodes can be part of the Stellar testnet.

Joining the network

After reviewing the existing configuration and comparing the live network attributes defined in the compose file, I felt I had a decent idea of what I needed to do to join as another node in the Stellar network. The key areas I focused on what the existing peer networks and nodes as well as how to retrieve history of the transaction activity on Stellar testnet. The result is an updated compose yaml file that maps to the Stellar testnet.

Friendbot

The testnet includes a service that allows developers to quickly create stellar accounts called Friendbot. I will use this service to create a new account on the testnet. This will allow me to verify the account exists in my local node and ensure that I have established consensus with the greater testnet nodes.

Friendbot create and fund a test account

I can now verify the account has been created using the horizon UI as well as retrieve the ledger the account creation was committed on.

Account obtained from public testnet horizon UI

Establishing quorum

To verify that our local nodes are synching with the global Stellar testnet, Stellar provides a metrics endpoint that includes the latest ledger that the local nodes are aware of. What I have found is the initial quorum takes time to establish but once the nodes are caught up, the network is really responsive in terms of ensuring quorum. You will know the ledger is caught up when the ledger number is greater than the ledger the transaction was included in. Using the metrics endpoint http://localhost:80000/metrics, you can verify the account was included as part of the ledger 103514 and the metrics endpoint denotes the local ledger is now at 103581.

Verifying accounts

Now that we have established quorum, we can now retrieve the account we created on the testnet using our local Stellar nodes. To retrieve the specific account, the http API is in the format http://localhost:8000/account/$publickey

Here is the result of the account that we created using Friendbot previously.

As you can see in the response, the local node is aware of the recently created account and we have established quorum for this ledger transaction.

Putting it all together

Now that have verified that we have achieved consensus on the latest transactions, we can start to leverage the Stellar SDK to drive various API calls and verify we can exercise the features of Stellar. To demonstrate this, I wrote two example flows called simpleFlow and multiSigFlow that leverage most of the key features of the Stellar SDK.

Conclusion

In this article, I walked through how to configure a local testnet node for Stellar leveraging Docker Compose. While the time to build consensus requires some patience at first, the benefits of having a local testnet for testing and development is worth it. For access to the complete set of resources that were used in this article, check out my GitHub project stellar-testnet.