Registering a namespace

Create a unique place for your assets.

Prerequisites

Method #01: Using the SDK

  1. Choose a unique name for your namespace. One common option is to use your company’s or own name.
  2. In this example, we are going to register a namespace named foo. Check if your namespace name is available.
const namespace = new NamespaceId('foo');

const namespaceHttp = new NamespaceHttp('http://localhost:3000');
namespaceHttp
    .getNamespace(namespace)
    .subscribe(namespace => console.log(namespace), err => console.error(err));
const namespace = new nem2_sdk_1.NamespaceId('foo');
const namespaceHttp = new nem2_sdk_1.NamespaceHttp('http://localhost:3000');
namespaceHttp
    .getNamespace(namespace)
    .subscribe(namespace => console.log(namespace), err => console.error(err));
nem2-cli namespace info --name foo
  1. Is the namespace available? Try to register it before someone else does it! Announce a NamespaceRegistrationTransaction with the chosen name and renting duration expressed in blocks.
const namespaceName = "foo";
const namespaceRegistrationTransaction = NamespaceRegistrationTransaction.createRootNamespace(
    Deadline.create(),
    namespaceName,
    UInt64.fromUint(1000),
    NetworkType.MIJIN_TEST);

const privateKey = process.env.PRIVATE_KEY as string;
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST);
const networkGenerationHash = process.env.NETWORK_GENERATION_HASH as string;
const signedTransaction = account.sign(namespaceRegistrationTransaction, networkGenerationHash);

const transactionHttp = new TransactionHttp('http://localhost:3000');
transactionHttp
    .announce(signedTransaction)
    .subscribe(x => console.log(x), err => console.error(err));
const namespaceName = "foo";
const namespaceRegistrationTransaction = nem2_sdk_1.NamespaceRegistrationTransaction.createRootNamespace(nem2_sdk_1.Deadline.create(), namespaceName, nem2_sdk_1.UInt64.fromUint(1000), nem2_sdk_1.NetworkType.MIJIN_TEST);
const privateKey = process.env.PRIVATE_KEY;
const account = nem2_sdk_1.Account.createFromPrivateKey(privateKey, nem2_sdk_1.NetworkType.MIJIN_TEST);
const networkGenerationHash = process.env.NETWORK_GENERATION_HASH;
const signedTransaction = account.sign(namespaceRegistrationTransaction, networkGenerationHash);
const transactionHttp = new nem2_sdk_1.TransactionHttp('http://localhost:3000');
transactionHttp
    .announce(signedTransaction)
    .subscribe(x => console.log(x), err => console.error(err));

Note

To keep the ownership of your namespace, you will have to extend its duration before it expires.

Method #02: Using the CLI

nem2-cli transaction namespace --name foo --rootnamespace --duration 1000

What’s next?

When the transaction is confirmed, register a subnamespace following the next guide.