Nano Messages

Write and read messages in the Nano blockchain

Cristian Livella
10 min readJan 22, 2021

Introduction — What is Nano? What’s wrong with Bitcoin?

At the end of 2008 a person known as Satoshi Nakamoto released the Bitcoin Whitepaper, a document that theorizes “A Peer-to-Peer Electronic Cash System”.

The idea was to develop a system to allow online payments without having to rely on third-party financial institutions. Over the years, more and more people and companies have begun to take an interest in Bitcoin, to the point of considering it as the digital gold.

However, as the years go by, Bitcoin is starting presenting some problems that are making it unusable as a global cash system:

  1. Due to the size of the blocks, Bitcoin can elaborate on average about only 7 TPS (transactions per second). Just for a simple comparison, Mastercard, Visa and Paypal during the year 2019 have processed overall 238 billion of transactions, then on avarage more then 7500 TPS
  2. When sending Bitcoin transactions the user can choice the amount of the transaction fee; the higher it is, the faster the transaction will be processed. Due to the low number of transactions per second that can be processed, users keep increasing the fees to get more priority. At the time of writing, the average transaction fee in the last 3 months is about $6. Imagine buying a coffee and pay $3 for it and $6 transaction fee… absolutely inconvenient.
  3. Due to the long and complex mining process and the low number of TPS, a transaction takes a long time to complete. In the best case 5–10 minutes, but due to the perennial congestion of the network, the average time before the transaction is completed is 60–120 minutes.
  4. The huge infrastructure for Bitcoin mining has very high power consumption, it is estimated that around 75 TWh were consumed in 2020, that is almost 100 KWh per transaction! This makes Bitcoin a very anti-environmental way to exchange money.
One of many Bitcoin mining farm. Bitcoin needs a lot of computational power to validate transactions. Picture by Marco Krohn, CC BY-SA 4.0, via Wikimedia Commons.

There are currently thousands of cryptocurrencies that are trying to compete with Bitcoin, but so far none have been able to do so, because most of them have similiar problems too.

A few months ago, however, I discovered Nano, which is in my opinion the best cryptocurrency to be used as a payment system, because:

  1. it’s very fast: at the moment the average transaction confirmation time is 0.11 seconds;
  2. it’s c̶h̶e̶a̶p free: there is no transaction fees at all;
  3. it’s scalable: according to the last tests, Nano can elaborate in average 1200 transactions per second, and could improve in the future as the speed of SSD and network increases.
Comparison of fees and speed between Bitcoin, Nano and DigiByte. https://twitter.com/patrickluberus/status/1257807071405367307

Due to these advantages, the use of Nano as a payment system is spreading day by day, and in the meantime some users are developing side projects to show how easy and fast Nano is.

These are some examples:

I also wanted to make a project to show how awesome Nano is, so I developed Nano Messages.

What is Nano Messages?

Nano Messages is a web application that allow to read and write messages in the Nano blockchain in a simple and fast way.

The result is a multi channel, decentralized and uncensorable message board.

You can try it by clicking here, or find out how it works by continuing to read this post.

Nano Messages web app

Where and how the messages are actually stored?

Yes, okay, I said that the messages are in the Nano blockchain… but how?

Basically, when you send a transaction, the fields you need to fill in are the recipient wallet address and the amount of Nano to send.

Both of these fields can be used to contain properly encoded data: the recipient address field can contain 256 bits of data (about 32 1-byte encoded characters), while the amount field can contains a variable amount of data, based on how many Nano you can afford to spend. Nano amount has 30 decimal digits, so with 1 Nano (about $3 at the time of writing) you can encode about 99 bits (12 characters).

It’s evidient that is more convenient to use the address field, as it can contain more data and there is no need to own a large amount of Nano (the minimum amount for a transaction is 10^-30 Nano, which is called 1 raw and at the moment it’s worth around $0.00 — nothing).

How are the wallet addresses made?

This is an example of a Nano wallet address:

  • Every Nano address starts with nano_ (or xrb_ as Nano was previously called RaiBlocks).
  • The next 52 characters are the real important part, as they are basically the encoded public key of the Nano wallet. The first character of this part can be only 1 or 3, while the others 51 characters can be any character of this special alphabet: “13456789abcdefghijkmnopqrstuwxyz”. We are going to ignore the first character and use only the others 51 to encode our messages.
  • Finally, the last 8 characters are a checksum, to check that the address is valid and prevent to erroneously send funds to a wrong address, by mistyping some characters.

How are messages encoded in wallet addresses?

Messages are encoded in a very simple way: every character in the message is firstly represented as 1 byte, using a small subset of the UTF-16 encoding, the first 256 characters rappresentable. Here you can find a table with the binary rappresentation of each character, just ignore the first 8 bits.

After that, the bits are divided into groups of 5, and each group is then rappresented as the corresponding character in the alphabet used in the Nano addresses (13456789abcdefghijkmnopqrstuwxyz). So 00000 = 1, 00001 = 3, 00010 = 4, and so on…

Let’s see an example of the encoding of the message “Hello!”:

# UTF-16 1 byte rappresentation
01001000 01100101 01101100 01101100 01101111 00100001
H e l l o !
# base32 Nano address rappresentation
01001 00001 10010 10110 11000 11011 00011 01111 00100 00100
b 3 k p r u 5 h 6 6

“Hello!” = “b3kpru5h66”. It’s that simple, no weird or complicated algorithm. You can also encode and decode short messages by hand.

Note that I added 2 zero bits at the end, to make also the last group 5 bit long.

To be able to reppresent the messages as a wallet address it must be 51 characters long, so I added some extra spaces at the end of the plain message to make it 50 character long, and I added a random character at the end (because 255, the number of bits we are using in the address, is not divisible by 8, the bits length of each character, it’s not possible to have 51 characters encoded message).

So this is what it looks like in the end:

b3kpru5h66i41a3161i41a3161i41a3161i41a3161i41a31619

Finally, we have to calculate the address checksum using BLAKE2b, and we have all we need to make the complete address:

nano_1b3kpru5h66i41a3161i41a3161i41a3161i41a3161i41a31619ijghkiwh

Note that the character 1 after nano_ it was chosen arbitrarily and it doesn’t depend on the message, as we have decided for convenience not to use it. It could also be 3 without any problem.

That looks nice, we just have to send a transasction to that address and we just put a message in the Nano blockchain! But there are 2 problems:

  1. for what we saw until now, we can only send message up to 31 characters long, as a 32 character message will be encoded in 52 base32 characters, and that’s too long for a wallet address;
  2. other peoples are unlikely to find our message in the blockchain, as it apparently it looks like a normal transaction, sent to a normal address.

Now we’ll se how to solve those two problems!

Message in multiple transactions

The problem of the message length it’s quite easy to solve, it’s enough to split the message in more wallet addresses, and so in many transactions.

The message will be encoded as we have seen before and then it will be splitted in chunks of 51 characters. Even in this case, if the message it’s too short to fill the last address, some space characters will be added at the end, and an extra random character if needed to get 51 character.

For example, the message “Lorem ipsum dolor sit amet, consectetur adipisci elit” encoded with the proper padding is:

bjqq6sdf63nq1wuofni8auuefxs41wubgii84ud7gip41ruhfsspcruneot9cwj1e7k8kw5bgfjpka57fjnqaa3161i41a3161i419

It’s 102 characters long, and exactly fill 2 wallet addresses.

In this way we can theoretically send messages of any length, but I preferred to set a limit of 50 transactions/blocks for each message in Nano Messages, that is equivalent to 1593 characters, to prevent too long messages.

However, as the message can now be splitted in various transactions, it is necessary to introduce a system to know the length of the messages, and to ensure that the whole message was correctly sended and received.

So I introduced the checksum transaction, that will be send at the end of the message, and the address will contain the size in blocks of the message, and a checksum to ensure that the message received is complete.

The checksum block

The checksum message it looks like this:

n|sha256sum

where n is the number of transactions that contain the message chunks, and sha256sum is the first piece of the SHA-256 hash of the message.

The SHA-256 hash is truncated to fill the available space in a wallet address, so its length various with the length of n.

For example, the checksum message for the message “Lorem ipsum dolor sit amet, consectetur adipisci elit” is this:

2|1a83ba1a20b8d69843d51febc4b45

It is also encoded with the same algorithm as the message, and therefore becomes this address:

nano_18by54rbr8fj84ed38ar86g568rwmif3meitm4sm7ebjmarjn8n9hsz4rsxh

So, to send the message “Lorem ipsum dolor sit amet, consectetur adipisci elit” we have to send 3 transactions to these addresses:

nano_1bjqq6sdf63nq1wuofni8auuefxs41wubgii84ud7gip41ruhfss88g1aieb
nano_1pcruneot9cwj1e7k8kw5bgfjpka57fjnqaa3161i41a3161i419w1nd6px6
nano_18by54rbr8fj84ed38ar86g568rwmif3meitm4sm7ebjmarjn8n9hsz4rsxh

How to make people find the message

The second problem is this: we sent the message, but how can we retrieve it, among the other thousands of transactions in the Nano blockchain?

We can send a transaction to a know wallet address, and in this way by looking the funds sent to that address, we can know that in the sender transactions history there’s a message!

But, to do something better, I designed a way to send messages in different channels, and that’s is possible by encoding the channel name as we saw before, and use it to send this broadcast transaction.

For example, this is the address of the channel “global”:

nano_1nanomsg1exp8yrm3fii41a3161i41a3161i41a3161i41a3161ibrdgnkby

As you can see, it starts with nano_1nanomsg1, that’s a way to distinguish channel address from the messages address. Then, the words “global” is encoded in the same way of the messages, using the remaining bits in the address. That means that the maximum length of a channel is 25 characters. To allow easier access to a channel, the name is converted to lowercase, so it’s case insensitive (global = GLOBAL = GlObAl).

In addition, to prevent excessive spam, a minimum Nano amount has been set for the transactions sent to the channel address to be displayed on Nano Messages. At the moment the amount is 0.00019, that’s equivalent to $0.0006 at the time of writing.

Let’s recap the messages sending process

  1. The message is encoded using the Nano custom base32 encoding;
  2. the encoded message is splitted into chunks of 51 characters, each chunk made up a wallet address and a transaction is sent to each of them;
  3. a checksum message is generated, containing the number of chunks of the message and a partial SHA-256 hash;
  4. the checksum messages is encoded too, and a transaction is sent to the wallet address computed;
  5. finally, a transaction with a fixed minimum amount of Nano is sent to the channel address, computed by encoding its name.

That’s it!

In the following image you can see the transactions sent in order to publish the following message, excerpt from the Nano whitepaper.

Here we introduce Nano, a cryptocurrency with a novel block-lattice architecture where each account has its own blockchain, delivering near instantaneous transaction speed and unlimited scalability.

What about reading messages?

The process of retrieving messages from the blockchain is quite easy and intuitive:

  1. the channel address is computed, based on the channel name;
  2. the transactions list of the channel, that contains the broadcast blocks, is fetched from a Nano node;
  3. for each message, the transactions list of the sender is fetched, and with the recipients addresses of the transactions is possible to decode the message, in the opposite way it was encoded.

Do you want try Nano Messages?

If you want to try reading and writing messages on the Nano blockchain, you can try Nano Messages here: https://cristianlivella.github.io/nano-messages.

If you want just play around with the encoding system, without send real messages, you can use this demo: https://cristianlivella.github.io/nano-messages/#/demo.

I don’t have any Nano, where can I get them?

If you don’t have any Nano, the first thing you have to do is download a Nano wallet, like Natrium or Nault.

Then you can buy some Nano on an exchange, like Kraken, or get a small amount of it for free using nano-faucet.org or freenanofaucet.com.

Do you want learn more about Nano?

In this post I said that Nano is better of Bitcoin as a distributed payment system, but I didn’t tell why. If you want to learn more about Nano and understand why is so revolutionary, I suggest you to read these posts:

[1] Mastercard 87.3 B (https://cutt.ly/hjDm7I3); Visa 138.3 B (https://cutt.ly/3jDQqcw); PayPal 12.4 B (https://cutt.ly/NjDQeJ4).

--

--

Cristian Livella

Appassionato di tecnologia. Studente di informatica presso Università degli Studi di Milano Bicocca. Full stack developer presso Fatture in Cloud.