The snippet reads the signer's private key from the SIGNER_PRIVATE_KEY environment variable, which defaults to a
test key if not set.
The signer's address is derived from the public key.
This account will own the registered namespace.
# Fetch current network timetime_path='/node/time'print(f'Fetching current network time from {time_path}')withurllib.request.urlopen(f'{NODE_URL}{time_path}')asresponse:response_json=json.loads(response.read().decode())receive_timestamp=(response_json['communicationTimestamps']['receiveTimestamp'])timestamp=NetworkTimestamp(int(receive_timestamp))print(f' Network time: {timestamp.timestamp} ms since nemesis')# Fetch recommended feesfee_path='/network/fees/transaction'print(f'Fetching recommended fees from {fee_path}')withurllib.request.urlopen(f'{NODE_URL}{fee_path}')asresponse:response_json=json.loads(response.read().decode())median_mult=response_json['medianFeeMultiplier']minimum_mult=response_json['minFeeMultiplier']fee_mult=max(median_mult,minimum_mult)print(f' Fee multiplier: {fee_mult}')
# Build the transactionnamespace_name=f'ns_{int(time.time())}'print(f'Creating root namespace: {namespace_name}')transaction=facade.transaction_factory.create({'type':'namespace_registration_transaction_v1','signer_public_key':signer_key_pair.public_key,'deadline':timestamp.add_hours(2).timestamp,'registration_type':'root','duration':86400,# approximately 30 days'name':namespace_name})transaction.fee=Amount(fee_mult*transaction.size)
// Build the transactionconstnamespaceName=`ns_${Date.now()}`;console.log('Creating root namespace:',namespaceName);consttransaction=facade.transactionFactory.create({type:'namespace_registration_transaction_v1',signerPublicKey:signerKeyPair.publicKey.toString(),deadline:timestamp.addHours(2).timestamp,registrationType:'root',duration:86400n,// approximately 30 daysname:namespaceName});transaction.fee=newmodels.Amount(feeMult*transaction.size);
The namespace registration transaction specifies:
Type: Namespace registration transactions use the type namespace_registration_transaction_v1.
Registration type: The value root indicates a root namespace is being created.
Use child to register a subnamespace instead.
Duration: The number of blocks for which the namespace will be leased.
The minimum duration is 86,400 blocks (approximately 30 days), and the maximum is
5,256,000 blocks (approximately 5 years).
Name: The name of the root namespace.
Names can only contain lowercase letters, numbers, hyphens, and underscores, must start with a letter or number,
and can be at most 64 characters long.
To ensure the namespace name is unique across multiple runs of the tutorial, a timestamp is added to the name.
In practice, programs would use a fixed name for their namespaces.
Namespace lease fees
In addition to the standard transaction fee,
registering a namespace requires a lease fee proportional to
the requested duration.
Unlike the transaction fee, the lease fee is not included in the transaction request.
It is calculated and deducted automatically by the network from the transaction signer’s account
when the registration transaction is confirmed.
The amount of the lease fee can be calculated beforehand using the /network/fees/rentalGET endpoint.
// Retrieve the namespaceconstnamespaceId=generateNamespaceId(namespaceName);console.log('Namespace ID:',`${namespaceId} (0x${namespaceId.toString(16)})`);constnamespacePath=`/namespaces/${namespaceId.toString(16)}`;console.log('Fetching namespace information from',namespacePath);constnamespaceResponse=awaitfetch(`${NODE_URL}${namespacePath}`);constnamespaceJSON=awaitnamespaceResponse.json();constnamespaceInfo=namespaceJSON.namespace;console.log('Namespace information:');console.log(' Registration type:',namespaceInfo.registrationType);constownerAddress=newmodels.Address(Uint8Array.from(Buffer.from(namespaceInfo.ownerAddress,'hex')));console.log(' Owner address:',ownerAddress.toString());console.log(' Start height:',namespaceInfo.startHeight);console.log(' End height:',namespaceInfo.endHeight);
To verify the namespace was registered, the code retrieves it from the network
using the /namespaces/{namespaceId}GET endpoint and displays its properties.
The namespace ID is computed using .
This function applies a deterministic hashing algorithm to the namespace name,
producing the ID needed to query the namespace information.
A successful response confirms the namespace was registered and is active on the network.
Namespace registered but not linked yet
A namespace becomes useful when it serves as an alias for a mosaic or an account.
Link the namespace to an identifier using the guides in Next Steps.
Using node https://reference.symboltest.net:3001
Signer address: TCHBDENCLKEBILBPWP3JPB2XNY64OE7PYHHE32I
Fetching current network time from /node/time
Network time: 99282614227 ms since nemesis
Fetching recommended fees from /network/fees/transaction
Fee multiplier: 100
Creating root namespace: ns_1766533079
Built transaction:
{
"signature": "64F716B9F4CB265D7130FDBD6BABB93A3AE2CC31896D0D3C85DE7CAFDE3CC5053730FC56FCF64B3FCFD24213A9BF3432AC08D2C03766EAF847C86421D88EA603",
"signer_public_key": "3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29",
"version": 1,
"network": 152,
"type": 16718,
"fee": "15900",
"deadline": "99289814227",
"duration": "86400",
"id": "10704093651797406551",
"registration_type": 0,
"name": "6e735f31373636353333303739"
}
Transaction hash: 2E3ACFD140AEAA21E7839376C4290695E9E58761DC37B1E60D3207F76370CC22
Announcing namespace registration to /transactions
Response: {"message":"packet 9 was pushed to the network via /transactions"}
Waiting for namespace registration confirmation...
Transaction status: unconfirmed
Transaction status: unconfirmed
Transaction status: confirmed
Namespace registration confirmed in 11 seconds
Namespace ID: 10704093651797406551 (0x948c9476ade5f357)
Fetching namespace information from /namespaces/948c9476ade5f357
Namespace information:
Registration type: 0
Owner address: TCHBDENCLKEBILBPWP3JPB2XNY64OE7PYHHE32I
Start height: 2984442
End height: 3073722
Some highlights from the output:
Namespace name (line 7): The chosen name ns_1766533079 includes a timestamp to ensure uniqueness.
Search for this name in the Symbol Testnet Explorer to view the namespace details.
Fee (line 15): The transaction fee of 0.0159 XYM is calculated as the transaction size
multiplied by the fee multiplier. The lease fee is deducted separately
by the network when the transaction is confirmed.
ID and name (lines 18, 20): The id field shows the namespace ID as a decimal number, while name contains
the namespace name encoded as a hexadecimal string. For example, 6e735f... decodes to ns_1....
Namespace ID (line 30): Shows both decimal and hexadecimal representations to match the id field on line 18.
Registration type (line 33): The value 0 indicates a root namespace (versus 1 for subnamespaces).
Owner address (line 34): The account that registered and owns the namespace.
Start and end heights (lines 35-36): The namespace is active from block 2984442 to block 3073722.
The end height includes a grace period (1 day on testnet,
30 days on mainnet) beyond the requested duration, giving owners time to renew before the namespace
becomes available to others.
The transaction hash printed in the output can also be used to search for the transaction
in the Symbol Testnet Explorer.