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.
// replace with namespace name
const namespaceId = new NamespaceId('foo');
// replace with node endpoint
const nodeUrl = 'http://api-xym-harvest-3-01.us-west-2.nemtech.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const namespaceHttp = repositoryFactory.createNamespaceRepository();

namespaceHttp
    .getNamespace(namespaceId)
    .subscribe((namespaceInfo) => console.log(namespaceInfo), (err) => console.error(err));
// replace with namespace name
const namespaceId = new nem2_sdk_1.NamespaceId('foo');
// replace with node endpoint
const nodeUrl = 'http://api-xym-harvest-3-01.us-west-2.nemtech.network:3000';
const repositoryFactory = new nem2_sdk_1.RepositoryFactoryHttp(nodeUrl);
const namespaceHttp = repositoryFactory.createNamespaceRepository();
namespaceHttp
    .getNamespace(namespaceId)
    .subscribe((namespaceInfo) => console.log(namespaceInfo), (err) => console.error(err));
        try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
            "http://api-xym-harvest-3-01.us-west-2.nemtech.network:3000")) {
            // replace with namespace name
            final NamespaceId namespaceId = NamespaceId.createFromName("foo");

            final NamespaceRepository namespaceRepository = repositoryFactory
                .createNamespaceRepository();

            final NamespaceInfo namespaceInfo = namespaceRepository.getNamespace(namespaceId)
                .toFuture()
                .get();
            final Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
            System.out.println(gson.toJson(namespaceInfo));
        }
    }
nem2-cli namespace info --namespace-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.
// replace with namespace name
const namespaceName = 'foo';
// replace with duration (in blocks)
const duration = UInt64.fromUint(1000);
// replace with network type
const networkType = NetworkType.TEST_NET;

const namespaceRegistrationTransaction = NamespaceRegistrationTransaction.createRootNamespace(
    Deadline.create(),
    namespaceName,
    duration,
    networkType,
    UInt64.fromUint(2000000));

// replace with private key
const privateKey = '1111111111111111111111111111111111111111111111111111111111111111';
const account = Account.createFromPrivateKey(privateKey, networkType);
// replace with meta.generationHash (nodeUrl + '/block/1')
const networkGenerationHash = '45870419226A7E51D61D94AD728231EDC6C9B3086EF9255A8421A4F26870456A';
const signedTransaction = account.sign(namespaceRegistrationTransaction, networkGenerationHash);
// replace with node endpoint
const nodeUrl = 'http://api-xym-harvest-3-01.us-west-2.nemtech.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();

transactionHttp
    .announce(signedTransaction)
    .subscribe((x) => console.log(x), (err) => console.error(err));
// replace with namespace name
const namespaceName = 'foo';
// replace with duration (in blocks)
const duration = nem2_sdk_1.UInt64.fromUint(1000);
// replace with network type
const networkType = nem2_sdk_1.NetworkType.TEST_NET;
const namespaceRegistrationTransaction = nem2_sdk_1.NamespaceRegistrationTransaction.createRootNamespace(nem2_sdk_1.Deadline.create(), namespaceName, duration, networkType, nem2_sdk_1.UInt64.fromUint(2000000));
// replace with private key
const privateKey = '1111111111111111111111111111111111111111111111111111111111111111';
const account = nem2_sdk_1.Account.createFromPrivateKey(privateKey, networkType);
// replace with meta.generationHash (nodeUrl + '/block/1')
const networkGenerationHash = '45870419226A7E51D61D94AD728231EDC6C9B3086EF9255A8421A4F26870456A';
const signedTransaction = account.sign(namespaceRegistrationTransaction, networkGenerationHash);
// replace with node endpoint
const nodeUrl = 'http://api-xym-harvest-3-01.us-west-2.nemtech.network:3000';
const repositoryFactory = new nem2_sdk_1.RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
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.