Dive into Nebulas 3 — Managing Accounts
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.
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:
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.
All addresses in Nebulas consist of three parts: header, raw data and checksum.
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:
- 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’.
- 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: [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:
- Generate private key randomly.
- Derive the public key from the private key.
- Derive the raw address data from the public key.
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.
In this section, I’ll share three methods on how to generate a new account in Nebulas.
This is the easiest way to create an account with Nebulas Web Wallet.
- Download the repo.
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.
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.
And your keystore file will be locate in: keydir/n1Nfk88RDecqXYjbh31nrfch4N1xxYi4mUf.
Neb.js can also be used to generate a new account.
- Download the repo.
git clone https://github.com/nebulasio/neb.js
2. Build this project and get ./dist/nebulas.js.
3. Create a simple page to include nebulas.js and open it in Chrome.
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.
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.