Member-only story

Validating Spacemesh Addresses

TickTockBent
2 min readJun 29, 2024

--

In order to check that I’m doing it right in my last article, and to validate new addresses entered by users, I decided to implement some simple address validation. Understanding and validating addresses is crucial for developers working with the Spacemesh ecosystem, and it can save you a lot of headaches down the road. This article will guide you through the process of validating Spacemesh addresses, complete with a straightforward Python implementation.

Requirements

Before we begin, ensure you have Python 3.7+ installed, along with the bech32 library.

pip install bech32

I covered the anatomy of a Spacemesh address in my last article, but I’ll go over it again briefly here.

A Spacemesh wallet address…

…starts with the prefix “sm1” for mainnet addresses (or “stest1” for testnet).
…has a total length of 48 characters. (51 for testnet, to accomodate the extended hrp)
…uses Bech32 encoding, which includes error-checking capabilities.
…when decoded, contains 24 bytes of data, with the first 4 bytes being zero.

Breakdown and Example

Knowing these things, in order to validate that an incoming string is also a valid Spacemesh address, we must…

  1. Check the prefix and length
  2. Decode the Bech32 address

--

--

TickTockBent
TickTockBent

Written by TickTockBent

I write a few unofficial articles to help understand Spacemesh but I am not affiliated with the team in any way.

No responses yet