Alias an address with a namespace so that others can reference the account in a more friendly way when issuing transactions.
symbol.xym
to pay for transaction fees.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);
// 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
.
// 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();
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
Did you find what you were looking for? Give us your feedback.