Ping21: Earn Bitcoin by Monitoring Uptime and Latency

Posted by Tyler Pate, Andrew DeSantis, Eli Haims

Ping21: Earn Bitcoin by Monitoring Uptime and Latency


In this tutorial we'll use the 21 Marketplace to discover and buy a simple ping service called ping21 from a distributed grid of network-connected devices. The diagram below shows how ping21 uses micropayments to rent multiple servers on a distributed grid to measure the latency and uptime from those servers to a specified IP address.

Ping21 data and bitcoin flow diagram

In this tutorial we will first go through how to buy the ping21 service for bitcoin as a buyer, and then how to set up a local device to offer ping21 services for bitcoin as a seller.


Install 21

You will need one of the following items:

  • Either a 21 Bitcoin Computer or 21
  • The latest version of the 21 software, obtained by running 21 update
  • A wallet, which can create by running 21 status
  • A connection to the 21market network, which you can connect to by running 21 market join

Finally, you will need some bitcoin to run these commands; if you don't have enough, just run the 21 sell command.

Step 1: Buy your first Ping21 from the marketplace

Open up a new terminal window. If you use a 21 Bitcoin Computer, ssh into it:

## Only necessary if you use a 21 Bitcoin Computer
ssh twenty@IP_ADDRESS

You can now query the ping21 service from the 21 marketplace with the 21 buy command. In this example, we are paying 3 machines around the world to ping the website and return information on whether (a) they can reach the site at all and (b) what the latency is from their geographic location to We pay 3000 satoshis per request per machine, so a total of 9000 satoshis.

21 buy 21dotco/ping21_aggregator/ping21/buypings --data '{"n": 3, "website": ""}'

As shown, the command takes the domain you desire to ping and some bitcoin, and then hits an endpoint in the 21 marketplace. As shown below, it returns a JSON array of ping statistics from the ping21 servers that have joined the ping21 service.

    "pings": [
            "server": {
                "postal": "07747",
                "city": "Matawan",
                "org": "AS20473 Choopa, LLC",
                "ip": "",
                "region": "New Jersey",
                "hostname": "",
                "loc": "40.4169,-74.2579",
                "country": "US"
            "ping": [
                "PING ( 56 data bytes",
                "64 bytes from seq=0 ttl=52 time=90.382 ms",
                "64 bytes from seq=1 ttl=52 time=90.415 ms",
                "64 bytes from seq=2 ttl=52 time=90.395 ms",
                "--- ping statistics ---",
                "3 packets transmitted, 3 packets received, 0% packet loss",
                "round-trip min/avg/max = 90.382/90.397/90.415 ms"
            "server": {
                "postal": "01803",
                "city": "Burlington",
                "org": "AS701 MCI Communications Services, Inc. d/b/a Verizon Business",
                "ip": "",
                "region": "Massachusetts",
                "hostname": "",
                "loc": "42.5051,-71.2047",
                "country": "US"
            "ping": [
                "PING ( 64(92) bytes of data.",
                "72 bytes from icmp_seq=1 ttl=55 time=79.3 ms",
                "72 bytes from icmp_seq=2 ttl=55 time=80.2 ms",
                "72 bytes from icmp_seq=3 ttl=55 time=79.2 ms",
                "--- ping statistics ---",
                "3 packets transmitted, 3 received, 0% packet loss, time 2002ms",
                "rtt min/avg/max/mdev = 79.202/79.624/80.281/0.470 ms"
            "server": {
                "postal": "HP11",
                "city": "High Wycombe",
                "org": "AS2856 British Telecommunications PLC",
                "ip": "",
                "region": "England",
                "hostname": "",
                "loc": "51.6242,-0.7453",
                "country": "GB"
            "ping": [
                "PING ( 64(92) bytes of data.",
                "72 bytes from icmp_seq=1 ttl=52 time=143 ms",
                "72 bytes from icmp_seq=2 ttl=52 time=143 ms",
                "72 bytes from icmp_seq=3 ttl=52 time=143 ms",
                "--- ping statistics ---",
                "3 packets transmitted, 3 received, 0% packet loss, time 2001ms",
                "rtt min/avg/max/mdev = 143.590/143.794/143.936/0.462 ms"

You spent: 9000 satoshis. Remaining balance: 115250 satoshis.

Step 2: Set up your own Ping21 server and publish it to the 21 marketplace

You just saw how to buy the ping21 grid computing service for bitcoin. Now we're going to see how to sell it. Open up another new terminal window. If you use a 21 Bitcoin Computer, ssh into it:

## Only necessary ify ou use a 21 Bitcoin Computer
ssh twenty@IP_ADDRESS

Then install git if you do not have it already, and clone the Ping21 server code:

## If you use Linux
sudo apt-get install -y git
## If you use Mac OS X
sudo brew install git
## For both Linux and Mac
git clone
cd ping21

Next we will pull in and install ping21's dependencies and configure your ping21 manifest file to publish to the 21 marketplace.

sudo pip3 install -r requirements.txt
21 publish submit manifest.yaml -p 'name="Joe Smith" email="" price="5" host="AUTO" port="6002"'

Go ahead and substitute your own name and email in the text above. For more information about publishing new endpoints in the marketplace, please read the Marketplace documentation.

After you have published your new endpoint, run the server with the following command.

python3 -d

Note that if you shut down your device or turn off the flask server, the server will no longer be accessible. To re-start the server, navigate to the ping21 directory, and re-run python3 -d in the terminal.

Step 3: Verify your Ping21 endpoint is a member of the Ping21 service

We're now going to verify that the individual endpoint you just set up and published is a member of the ping21 grid computing service. In other words, we'll show you how to confirm that your machine be among those being rented out when purchases are made from

In theory, you could simply grep the output of ping21 to look for your IP. However, if you bought (say) from three ping21 servers out of one hundred total, you might not see your IP in the results and not know whether you are receiving revenue for renting out your computer.

The ping21 service has an endpoint that allows you to verify that your ping21 server is visible to the marketplace service. After starting your ping21 server as in step 2, open a new terminal window. If you use a 21 Bitcoin Computer, ssh into it:

## Only necessary if you use a 21 Bitcoin Computer
ssh twenty@IP_ADDRESS

First you must find your ZeroTier IP address. To do this, enter the following command:

21 market status

You will see an output that looks similar to this:

Network Name    Your IP
--------------  --------------

Locate the row that says 21 market and your IP address will be the number at the end of that line.

We will now contact the marketplace ping21 service to ask if it knows about this IP address. Run this command:


You will see one of two responses:

# Success!
Your ping server is in the ping21 pool. 
# Your ping server was not found
Your server is not in the ping21 pool.

Please check that your ping21 server has been published to the marketplace and is running.

If your ping server was not found, you can use the following steps to make sure that python3 -d is still running as an active process.

Open a new terminal. If you use a 21 Bitcoin Comptuer, SSH into it:

## Only necessary if you use a 21 Bitcoin Computer
ssh twenty@IP_ADDRESS

Now run the following command:

ps aux | grep "python3 [p]"

You should see at least one result returned if the server is still active.

If the server is not active, return to step 2 to start your server. If the server is active, wait a few minutes before verifying again. This gives the service some time for the crawler to add your IP address to the list of ping21 endpoints.

How it works

Ping21 uses the Python subprocess module to run a ping command and return the ping statistics to the server. The ping21 code spawns the ping subprocess, initiates the command, receives the statistics, and packages the information for consumption. In the process, ping21 also retrieves current server location data from a web service, IP Info.

The script starts a flask server that provides a ping21 endpoint. When queried, the server requests a payment and then pings any domain or IP provided, returning the location and timing information to the client.

When published to the 21 marketplace (as in Step 2) the server is aggregated with other similar endpoints into a single aggregated endpoint that can be purchased at (as in Step 1).

Next Steps

In this tutorial you learned how to buy and sell bitcoin-incentivized grid computing through the basic example of ping21. An obvious next step is to extend these ideas to other kinds of network utilities, like dig and traceroute that could also benefit from a distributed approach.

How to send your Bitcoin to the Blockchain

Just as a reminder, you can send bitcoin mined or earned in your balance to the blockchain at any time by running 21 flush . A transaction will be created within 10 minutes, and you can view the transaction id with 21 log. Once the transaction has been confirmed, you can check the balance in your bitcoin wallet from the command line with wallet balance, and you can send bitcoin from your wallet to another address with wallet sendto $BITCOIN_ADDRESS --satoshis $SATOSHI_AMOUNT --use-unconfirmed. The --satoshis flag allows you to specify the amount in satoshis; without it the sendto amount is in BTC, but this behavior is deprecated and will be removed soon. The --use-unconfirmed flag ensures that you can send even if you have unconfirmed transactions in your wallet.

Ready to sell your endpoint? Go to

Ready to try out your bitcoin-payable server in the wild? Or simply want to browse and purchase from other bitcoin-enabled servers? Head over to the 21 Developer Community at to join the bitcoin machine-payable marketplace hosted on the 21 peer-to-peer network.