Alias an address with a namespace so that others can reference the account in a more friendly way when issuing transactions.
Complete the getting started section.
Create a new account.
Load the account with enough symbol.xym
to pay for transaction fees.
Register a namespace with the account.
Click on “Namespaces” on the left-side menu.
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”.
Verify the information on the next page. Enter your wallet password. Click on “Confirm”.
If you linked the namespace to your desktop wallet account, you can check by going to the “Account” page and checking the “Alias”.
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);
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(epochAdjustment),
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 = 'NODE_URL';
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(epochAdjustment),
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 = 'NODE_URL';
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
.
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(epochAdjustment),
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(epochAdjustment),
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();
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