Dive into Nebulas 3 — Managing Accounts

Roy Shang
Nebulasio
Published in
3 min readMay 4, 2018

In this article, I’m happy to explain how managing accounts works in Nebulas. First, I’d like to share our address design method. If you’re more interested in knowing how to generate a new address, you can skip the first section.

Address

In Nebulas, each address represents an account. However, addresses in Nebulas a bit special compared to other blockchain projects.

Here is a typical address in Nebulas:

n1TV3sU6jyzR4rJ1D7jCAmtVGSntJagXZHC

It’s encoded in base58 just like Bitcoin, which help us reduce the size of raw data. Let’s decode it into hex string to figure out how it’s constructed.

19578E42761FDB43E9C5AD9CA93ACF1DDA6BE901F848AB3864AB

All addresses in Nebulas consist of three parts: header, raw data and checksum.

Header

header: [19 57]

The header consists of two magic numbers: a fixed number 0x19, and a variable number between 0x57 and 0xe5. This contains several types of information:

  1. It tells us if the address is a Nebulas address: the two numbers make all our encoded addresses begin with a lower letter ’n’ which represents ‘Nebulas’.
  2. It tells us if the address is a contract address: 0x58 indicates a contract address, whereas the second number 0x57 indicates the address is a non-contract address.

Raw Data

raw data: [8E 42 76 1F DB 43 E9 C5 AD 9C A9 3A CF 1D DA 6B E9 01 F8 48]raw data = derive(derive(random private key))[:20]

Raw address data is generated based on an elliptic curve algorithm similar to Bitcoin. The safety is proven by the stability of Bitcoin:

  1. Generate private key randomly.
  2. Derive the public key from the private key.
  3. Derive the raw address data from the public key.

Checksum

checksum: [AB 38 64 AB]checksum = sha3_256(header + raw)[:4]

We’ve heard so many stories of mistakenly transferred funds, so checksum is essential for each address. In Nebulas, we use checksum to check the correctness of both header and raw data. All effort to make your assets safer is deserved.

New Account

In this section, I’ll share three methods on how to generate a new account in Nebulas.

Web-Wallet

This is the easiest way to create an account with Nebulas Web Wallet.

  1. Download the repo.
git clone https://github.com/nebulasio/web-wallet.git

2. Open the index.html in this repo with your explorer. You’ll get this page.

3. Enter your own passphrase to create a new account. Then DOWNLOAD the keystore file and STORE it carefully.

Attention: Make sure your passphrase and keystore file are safe. Anyone can steal the money in your account if they have access to these two things.

Go-Nebulas

If you have built neb successfully according to this post, you can generate a new account with it easily.

All you need to do is run this command:

./neb account new

You’ll get this result:

Your new account is locked with a passphrase. Please give a passphrase. Do not forget this passphrase.
Passphrase:
Repeat passphrase:
Address: n1Nfk88RDecqXYjbh31nrfch4N1xxYi4mUf

And your keystore file will be locate in: keydir/n1Nfk88RDecqXYjbh31nrfch4N1xxYi4mUf.

Neb.js

Neb.js can also be used to generate a new account.

  1. Download the repo.
git clone https://github.com/nebulasio/neb.js

2. Build this project and get ./dist/nebulas.js.

npm install
gulp

3. Create a simple page to include nebulas.js and open it in Chrome.

<!doctype>
<html>
<head>
<script type=”text/javascript” src=”/path/to/nebulas.js”></script>
</head>
<body>
<h1>Demo</h1>
</body>
</html>

4. Open the console in Chrome’s developer tools and run these commands to generate a new account. You can save the keystore string into a keystore file and store it.

What’s Next?

Congratulations! You’ve now generated your own Nebulas accounts. Just a friendly reminder once again to please keep your passphrases and keystore files safe.

Next, I’ll show you how to send transactions with your accounts using safe methods.

--

--