Linking a namespace to an address

Alias an address with a namespace so that others can reference the account in a more friendly way when issuing transactions.

Prerequisites

Method #01: Using the Desktop Wallet

  1. Click on “Namespaces” on the left-side menu.
../../_images/desktop-link-address-1.gif
  1. Click on the edit icon of the namespace you desire to link to an account. Select “Link an address” as the alias type. Enter the address of the account you want to link to the namespace. Click “Send”.
../../_images/desktop-link-address-2.gif
  1. Verify the information on the next page. Enter your wallet password. Click on “Confirm”.
  2. If you linked the namespace to your desktop wallet account, you can check by going to the “Account” page and checking the “Alias”.
../../_images/desktop-link-address-3.gif

Method #02: Using the SDK

  1. Open a new file and define the namespace identifier and the address you want to alias.

Note

The account signing the transaction must own the namespace.

// replace with namespace name
const namespaceId = new NamespaceId('foo');
// replace with address
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = Address.createFromRawAddress(rawAddress);
// replace with namespace name
const namespaceId = new symbol_sdk_1.NamespaceId('foo');
// replace with address
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = symbol_sdk_1.Address.createFromRawAddress(rawAddress);
  1. Then, announce the AliasTransaction that links the namespace and the address.
// replace with network type
const networkType = NetworkType.TEST_NET;

const addressAliasTransaction = AliasTransaction.createForAddress(
    Deadline.create(),
    AliasAction.Link,
    namespaceId,
    address,
    networkType,
    UInt64.fromUint(2000000));

// replace with private key
const privateKey = '1111111111111111111111111111111111111111111111111111111111111111';
const account = Account.createFromPrivateKey(privateKey, networkType);
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
const networkGenerationHash = '1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
const signedTransaction = account.sign(addressAliasTransaction, networkGenerationHash);
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.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 network type
const networkType = symbol_sdk_1.NetworkType.TEST_NET;
const addressAliasTransaction = symbol_sdk_1.AliasTransaction.createForAddress(symbol_sdk_1.Deadline.create(), symbol_sdk_1.AliasAction.Link, namespaceId, address, networkType, symbol_sdk_1.UInt64.fromUint(2000000));
// replace with private key
const privateKey = '1111111111111111111111111111111111111111111111111111111111111111';
const account = symbol_sdk_1.Account.createFromPrivateKey(privateKey, networkType);
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
const networkGenerationHash = '1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
const signedTransaction = account.sign(addressAliasTransaction, networkGenerationHash);
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
transactionHttp
    .announce(signedTransaction)
    .subscribe((x) => console.log(x), (err) => console.error(err));

Note

If you want to unlink the alias, change alias action type to AliasActionType.Unlink.

  1. Now you can send transactions to the namespace linked to the account instead of using the complete address.
// Replace with network type
const networkType = NetworkType.TEST_NET;
// Replace with aliased address
const recipientAddress = new NamespaceId('foo');

TransferTransaction.create(
    Deadline.create(),
    recipientAddress,
    [],
    EmptyMessage,
    networkType,
    UInt64.fromUint(2000000));
// Replace with network type
const networkType = symbol_sdk_1.NetworkType.TEST_NET;
// Replace with aliased address
const recipientAddress = new symbol_sdk_1.NamespaceId('foo');
symbol_sdk_1.TransferTransaction.create(symbol_sdk_1.Deadline.create(), recipientAddress, [], symbol_sdk_1.EmptyMessage, networkType, symbol_sdk_1.UInt64.fromUint(2000000));
            final NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
            // replace with aliased address
            final String namespaceName = "foo";
            final UnresolvedAddress recipientAddress = NamespaceId.createFromName(namespaceName);

            TransferTransactionFactory
                    .create(
                            networkType,
                            recipientAddress,
                            Collections.emptyList(),
                            PlainMessage.Empty)
                    .maxFee(BigInteger.valueOf(2000000)).build();

Method #03: Using the CLI

To link a namespace and an address, open a terminal window and run the following command. Replace TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I with the account’s address and foo with the namespace name to be linked.

Note

The account signing the transaction must own the namespace.

symbol-cli transaction addressalias --action Link --address TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I --namespace-name foo