Namecoin is an old crypto-currency, one of the original forks of Bitcoin. It still exists today and has good security, primarily because it can be merge-mined with Bitcoin.

This means that Namecoin latches on to the mining power of the Bitcoin blockchain, and in return, Bitcoin miners are rewarded with Namecoin and Bitcoin at the same time. Namecoin isn't worth much, and there is currently only one exchange trading it, the NMC/BTC trading pair on livecoin.net. However, it's worth enough to be merge-mined, and that's a good thing, because it enables us to use Namecoin while enjoying the same strong consensus and proof-of-work guarantees that Bitcoin enjoys.

Brief Introduction to Bitcoin and crypto-currency in general

If you are unfamiliar with what Bitcoin is and how it works, the claims I'm about to make might be confusing or hard to believe. If that is the case for you, I would recommend reading the webcomic version of the original Bitcoin whitepaper on coinspice.io first.

Now, if you ARE familiar with Bitcoin, you may know that it's famous for being the 1st solution to a long-standing problem in computer science. In academia, this problem has been known as the Two Generals Problem or Byzantine Fault / Byzantine Generals Problem

Put simply, the problem asks:

How can two or more generals with geographically separated armies coordinate a synchronized attack, even if the generals don't necessarily trust each-other?

Note: The original version of this article had a highly inaccurate description of this problem. I have edited it with a better explanation.

It's a sort of game-theory problem where both self-interested parties have an incentive to cheat, but if they work together, the reward will be bigger.

Bitcoin solved this problem for the first time in 2009 by combining Public Key Cryptography and economically incentivized consensus, implemented as variably difficult Proof of Work that is incentivized, where the incentive "block reward" only continues to exist if others agree that the entire block (and all subsequent blocks) are valid. In general, this construction is referred to as a "Blockchain".

In a modern context, we can express the problem as:

How can we design software that allows multiple self-interested parties to read and write a shared database while eliminating the possibility of lying/cheating?

And that's exactly what Bitcoin does.

Why Namecoin? What problems does it solve?

Before Bitcoin, the Byzantine Generals Problem was unsolved. So all of the development of the internet and web technology that happened before then did not even attempt to guarantee no lying/cheating.

In general, problems where security was important, like

  • How can we make a global registry of domain names, and allow anyone to register a name?
  • How can HTTPS security certificates be proven authentic, while allowing anyone to get a certificate for their server?

were solved with appeals to authority. The scheme was something like,

  1. We will establish an authority organization, like a bank, to act as an intermediary.
  2. Users will ask this authority to enter a record in their database or sign a certificate.
  3. The client software (operating systems, embedded devices, web browsers, etc) will implicitly trust that whatever the authority says is true.

Some of these authority based solutions include:

These authority-solutions, primarily DNS, are used by governments around the world to monitor and censor internet use within and outside of their borders. Protestors in Turkey spray painted the IP addresses of Google's DNS servers on a wall, urging others to configure their computers to trust United States authorities for Domain Name information, rather than Turkish authorities, due to heavy censorship.

Within the United States, domains that host content which the government's corporate constituents don't like are regularly "seized". This means that the government threatens the DNS provider with legal action until the DNS provider (the technical "Authority", in this case) removes control of the DNS entry from the user and hands it over to the government. One government branch boasted over one million domains "seized" in 2018.

Secure Names Without Authority

However, now that we have a working solution to the Byzantine Generals Problem, we can actually do better at the technical level. Namecoin adds extra functionality on top of the payment functionality of Bitcoin, enabling users to participate in a distributed, secure, and global key-value database where keys and values cannot be "seized" or spoofed. Namecoin is a solution to another famous problem known as Zooko's Triangle, roughly expressed as:

Human-meaningful, Secure, and Decentralized. Pick Two.

With Namecoin, we can have all three.

This is a great improvement for modern and emerging web standards that have historically involved displaying large cryptographic numbers to users as a part of the protocol's user experience.

Examples include:

  • BitTorrent Magnet Links: magnet:?xt=urn:btih:5dee65101db281ac9c46344cd6b175cdcad53426
  • Bitcoin Addresses: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
  • Tor Hidden Services: http://3g2upl4pq6kufc4m.onion/
  • BitMessage Addresses: BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash
  • IPFS Name Records: /ipns/QmSrPmbaUKA3ZodhzPWZnpFgcPMFWF4QsxXbkWfEptTBJd

These are numbers, similar to IP addresses like 8.8.8.8 and 174.141.199.88, they are simply longer numbers that are encoded differently.

We can associate those long nonsense strings with human-meaningful names in Namecoin, and then anyone can access our resources by name as long as they have Namecoin-compatible client software on their computer.

Currently, support for Namecoin is being worked on within a number of projects, including the Tor Browser Project and IPFS!

So without further exposition, let's get into it!

Register a Namecoin .bit Domain easily, using Electrum-NMC

I did this on Linux, Ubuntu Focal (20) specifically, but it should work on Windows as well.

If you want to do this on Mac OS, you will probably run into problems. Some processes such as installing packages will be different, or may not work at all. If you have a Mac and you want to try this, it might be easier to simply use a Linux virtual machine. You can download a piece of software called VirtualBox for free from Oracle, which will allow you to run a Linux virtual machine from Mac OS or Windows.

Ingredients List

You are going to need:

  • Bitcoin to trade for NMC
  • A livecoin.net account to do the trade.
  • A computer or virtual machine running Linux or Windows, to run Electrum-NMC
  • Electrum-NMC software (Namecoin fork of Electrum Bitcoin Wallet)
  • Lots of time
    • Unfortunately due to software defaults that prioritize security over usability, several steps in this process require approximately two hours of waiting.
    • It's probably best to do this while you are doing something else.

Acquiring Bitcoin

Ask Satoshi Very Very Nicely.

JK. I'm not going to cover this here. There are plenty of other guides online regarding purchasing and storing Bitcoin. If all you want is to register a few names with Namecoin, you aren't going to need very much (Like, less than $10 worth). So security is not a very big deal here.

About Electrum and SPV Wallets

Electrum is one of the best Bitcoin wallets for new users, in my opinion. It is a Simple Payment Verification (SPV) wallet. This means that Electrum is not a Bitcoin "Full Node". It does not participate in the network by downloading and validating the entire bitcoin blockchain (Many gigabytes). Instead, it only downloads block headers and sparse transaction history for transactions that it cares about (addresses that it owns).

There are potential privacy concerns associated with SPV wallets, namely, that the wallet will contact a server in order to operate, and the person who owns that server will get to know that a specific IP address and/or client software profile owns specific addresses. This can be sensitive information, because with Bitcoin, Namecoin, and most other crypto-currencies, all transaction history is perfectly recorded and avaliable to the public forever.

But I don't care about that, I think it's fine for the world to know that I registered sequentialread.bit. Your use case may vary.

Aquiring and running Electrum-NMC

Electrum-NMC is a fork of Electrum which has been modified to support Namecoin instead of Bitcoin.

For more information, see: https://www.namecoin.org/docs/electrum-nmc/

You can download pre-compiled binaries of electrum-nmc for Linux and Windows here: https://www.namecoin.org/download/betas/#electrum-nmc

Unfortunately it looks like there are no official binaries for MacOS quite yet. If you have a Mac, you may be able to run it from the python source code easily enough, per the instructions on the README.

- Show [How to Run Electrum-NMC from Source] -

Creating the Electrum-NMC wallet file

The startup wizard will guide you through this process, I chose:

Wallet file location: /home/forest/Desktop/wallets/electrum_nmc_wallet

Note that if you put a tilde in the file name here, like ~/Desktop/... the file will end up in ~/.electrum/\~/Desktop/....

Similarly, if you enter mywallet, the file will be saved at ~/.electrum/mywallet

What kind of wallet do you want to create?: Standard wallet

Keystore: Create a new seed

Choose Seed type: Legacy

Why legacy? According to a user on the namecoin channel on matrix.org, livecoin.net currently only supports withdrawals to Legacy wallets.

After choosing these options, you will be prompted to write down the seed on paper. Keep this piece of paper SAFE! If you ever lose your wallet file, you can restore it from those seed words. Being able to read the seed words means you can spend the bitcoin/namecoin. So keep it safe and secure!

After that, you will be prompted to define a wallet password. This password protects the wallet file, making it harder for any potential malware on your computer to steal your Namecoins and your domain. I generated some random words for the password using https://pwm.sequentialread.com/ and wrote them down as well.

Finally, the wallet will open and you can accept NMC to be sent to it (Just use the View -> Show addresses menu)

Trading Bitcoin for NMC

It looks like currently (February 2020) the only trading platform that has an active community of folks trading NMC is the NMC/BTC trading pair on livecoin.net.

So I signed up for an account on livecoin.net to trade. They only require an email address to open an account there, if you are only trading crypto for crypto.

Then I used Electrum to deposit a small amount of Bitcoin with the livecoin.net custodial account.

Because livecoin.net requires 3 confirmations (3 blocks to be mined containing your transaction in a row) it takes about 30 minutes for the funds to be available on thier platform.

After that, I executed a trade for NMC on thier platform.

Finally, I transferred the NMC from the livecoin.net custodial account to the Electrum-NMC wallet.

Using Electrum-NMC to register/update a namecoin entry

This is actually super easy and straight forward. Under the Buy Names tab I entered 'd/sequentialread'

(the namecoin name record d/sequentialread represents the domain name sequentialread.bit)

I did notice sometimes the software throws an error while trying to check if a name is available. It looks like it was actually a rate-limiting RPC error from the Electrum-NMC server I was connected to, so definitely want to try again if it happens to you.

When you register a domain it pops up a modal dialog with two fields, Data and Transfer to.

Transfer to can be left blank unless you want to transfer ownership of the domain to someone else.

Data is a JSON object that contains all the values associated with this name in a standard format. You can use the DNS Editor button to create a valid Data value.

For more information on the Data value, see https://github.com/namecoin/proposals

For example, this is the JSON I used:

{"ip":"174.141.199.88", "map": {"*":{"alias":""}}}

This JSON instructs Namecoin compatible clients that this domain name (and all subdomains) are pointing to the IP address 174.141.199.88. The developer explained:

... basically stating that all the subdomains ("*") point to the same thing as [the 2nd-level-domain, in this case sequentialread.bit].

So in short, all the subdomains will also point to "ip":"174.141.199.88".

After submitting the Name registration request, I saw the Pre-registration transaction show up. But the actual name registration never showed up. I could not get anything to happen, so I gave up.

After a couple of days, a friend actually got me in contact with one of the Electrum-NMC developers, and he set me straight on what had happened:

Basically, when I wrote that code, I assumed that everyone was familiar with multi-step Bitcoin transaction protocols, in which it's typical to wait for quite a few blocks before broadcasting the next step. Obviously this was not a good assumption on my part.

In other words, the Electrum-NMC software was waiting for the 1st transaction (Pre-Registration, aka name_new) to be confirmed by a certain number of blocks being mined on top of it before it broadcasts the second transaction (Name Registration, aka name_firstupdate).

Aparently this process takes a really really long time. Like, hours. So you have to just let the Electrum-NMC application run in the background until the Registration transaction pops up. If you have to close and re-open it, that's fine. The developer told me:

FWIW, Electrum-NMC does save the next step of the registration procedure to its wallet file, so if you exit Electrum-NMC while a registration is pending, and then start it up again, it will still work fine. (At least it should. I don't test that use case often, but I tested it pretty thoroughly when that code was first written.)

Using the Electrum-NMC daemon's API to test your new .bit domain

For more information, see: https://www.namecoin.org/docs/electrum-nmc/#name-lookups

I wrote this little bash script to make this easier.

resolve-name-test.sh

#!/bin/bash

CONFIG_JSON="$(cat $HOME/.electrum-nmc/config)"  
DAEMON_PYTHON_LITERAL="$(cat $HOME/.electrum-nmc/daemon)"  
DAEMON_PORT="$(echo "$DAEMON_PYTHON_LITERAL" | sed -E 's/.*[^.0-9]([0-9]{4,7}\b).*/\1/')"  
curl -s "localhost:$DAEMON_PORT" 2>&1 > /dev/null  
DAEMON_REACHABLE_EXIT_CODE="$?"  
NAME_LOOKUP="$1"

if [ -z "$CONFIG_JSON" ]; then  
  CONFIG_JSON="$(echo "$CONFIG_JSON" | sed -E 's/"rpcpassword":\s*"[^"]+"/"rpcpassword": "*****"/')"
  echo "could not run because electrum-nmc config file was not found."
  echo "CONFIG_JSON=\"$CONFIG_JSON\" (expected a non-empty string)"
  exit 1
fi

if [ $DAEMON_REACHABLE_EXIT_CODE != 0 ]; then  
  echo 'This script requires the electrum-nmc daemon to be running. Try starting electrum-nmc first.'
  echo "DAEMON_PORT=\"$DAEMON_PORT\" (expected a non-empty string)"
  echo "DAEMON_REACHABLE_EXIT_CODE=$DAEMON_REACHABLE_EXIT_CODE (expected 0)"
  exit 1
fi

if [ -z $NAME_LOOKUP ]; then  
  echo "First argument (namecoin name key, for example 'd/mydomain', is required.) got '$NAME_LOOKUP'"
  exit 1
fi

USERNAME="$(echo "$CONFIG_JSON" | tr ',' '\n' | grep -E -o '\s*"rpcuser": "([^"]+)"' | sed -E 's|\s*"rpcuser": "([^"]+)".*|\1|')"  
PASSWORD="$(echo "$CONFIG_JSON" | tr ',' '\n' | grep -E -o '\s*"rpcpassword": "([^"]+)"' | sed -E 's|\s*"rpcpassword": "([^"]+)".*|\1|')"

CURL_OPTS_NOPASSWORDS="-sS -w \"%{http_code}\" -o /tmp/electrum-nmc-api-result.json"  
CURL_OPTS="$CURL_OPTS_NOPASSWORDS -u $USERNAME:$PASSWORD"  
CURL_RPC_BASE="curl $CURL_OPTS localhost:$DAEMON_PORT"  
CURL_RPC_BASE_NOPASSWORDS="curl $CURL_OPTS_NOPASSWORDS -u user:***** localhost:$DAEMON_PORT"  
REQUEST_JSON='{"id":"curltext","method":"name_show","params":["'"$NAME_LOOKUP"'"]}'  
echo ""  
echo "sending: $CURL_RPC_BASE_NOPASSWORDS -d \"$REQUEST_JSON\""  
STATUS_CODE="$($CURL_RPC_BASE -d "$REQUEST_JSON")"  
echo ""  
echo "status code: $STATUS_CODE"  
echo ""  
echo "result: $(cat /tmp/electrum-nmc-api-result.json | sed -E 's/([^\\])":\s*\{/\1":\n{/g' | sed -E 's/([^\\]["0-9]), /\1,\n/g')"  
rm /tmp/electrum-nmc-api-result.json 2>/dev/null

When I ran this the first time, I saw this:

forest@tower:~/Desktop/git/electrum-nmc$ ./resolve-name-test.sh d/sequentialread  
sending: curl -sS -w "%{http_code}" -o /tmp/electrum-nmc-api-result.json -u user:***** localhost:42669 -d "{"id":"curltext","method":"name_show","params":["d/sequentialread"]}"  
status code: "200"  
result: {"result": null, "id": "curltext",  
"error": {"code": -4, "message": "Name is purportedly unconfirmed"}
}

This is similar to the problem we ran into before with the Registration transaction that takes ages to show up. The error message says Name is purportedly unconfirmed

The Electrum-NMC developer told me:

Namecoin SPV clients such as Electrum-NMC don't trust name updates with fewer than 12 confirmations. The reasoning is that since SPV clients don't check ECDSA signatures (only PoW), we want to require a lot of PoW before we trust a transaction that could be used for, say, verifying a TLS certificate. Basically the danger of accepting an invalid transaction is potentially a lot higher for name lookups, so we're pretty careful about it. At some point (hopefully soon) I do plan to add ECDSA signature checks to Electrum-NMC for name lookups, at which point we probably won't require any confirmations at all for name lookups (we'll just make sure the signature chain goes back to a transaction for that name with at least 12 confirmations).

So, in other words, you have to wait for hours again. I was tired, so I went to sleep. The next day when I checked on it, it worked!

forest@thingpad:~/Desktop/git/electrum-nmc$ ./resolve-name-test.sh d/sequentialread

sending: curl -sS -w "%{http_code}" -o /tmp/electrum-nmc-api-result.json -u user:***** localhost:42669 -d "{"id":"curltext","method":"name_show","params":["d/sequentialread"]}"

status code: "200"

result: {"result":  
{"name": "d/sequentialread",
"name_encoding": "ascii",
"value": "{\"ip\":\"174.141.199.88\", \"map\": {\"*\": {\"ip\":\"174.141.199.88\"}}}",
"value_encoding": "ascii",
"txid": "4aeb6a76735038297c02ebfc6e901a0eb3ee34ce45490bf9a1b5d1ca13174f32",
"vout": 0,
"address": "N6dVSPm8Ex4ahyDg8mz48h4FSto87T557G",
"height": 525743,
"expires_in": 35986,
"expired": false, "ismine": null}, "id": "curltext",
"error": null}