Alias an mosaic with a namespace so that others can reference it 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 and mosaic being aliased.
// replace with namespace name
const namespaceId = new NamespaceId('foo');
// replace with mosaic id
const mosaicId = new MosaicId('7cdf3b117a3c40cc');
// replace with networkType
const networkType = NetworkType.TEST_NET;
const mosaicAliasTransaction = AliasTransaction.createForMosaic(
Deadline.create(),
AliasAction.Link,
namespaceId,
mosaicId,
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(mosaicAliasTransaction, 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 networkType
const networkType = symbol_sdk_1.NetworkType.TEST_NET;
const mosaicAliasTransaction = symbol_sdk_1.AliasTransaction.createForMosaic(symbol_sdk_1.Deadline.create(), symbol_sdk_1.AliasAction.Link, namespaceId, mosaicId, 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(mosaicAliasTransaction, 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 mosaicId
const mosaicId = new NamespaceId('foo');
TransferTransaction.create(
Deadline.create(),
Account.generateNewAccount(networkType).address,
[new Mosaic(mosaicId, UInt64.fromUint(10000000))],
EmptyMessage,
networkType,
UInt64.fromUint(2000000));
// replace with network type
const networkType = symbol_sdk_1.NetworkType.TEST_NET;
// replace with aliased mosaicId
const mosaicId = new symbol_sdk_1.NamespaceId('foo');
symbol_sdk_1.TransferTransaction.create(symbol_sdk_1.Deadline.create(), symbol_sdk_1.Account.generateNewAccount(networkType).address, [new symbol_sdk_1.Mosaic(mosaicId, symbol_sdk_1.UInt64.fromUint(10000000))], symbol_sdk_1.EmptyMessage, networkType, symbol_sdk_1.UInt64.fromUint(2000000));
final NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
// replace with aliased mosaic
final String namespaceName = "foo";
final NamespaceId mosaicId = NamespaceId.createFromName(namespaceName);
TransferTransactionFactory
.create(
networkType,
Account.generateNewAccount(networkType).getAddress(),
Collections.singletonList(
new Mosaic(mosaicId, BigInteger.valueOf(10000000))),
PlainMessage.Empty)
.maxFee(BigInteger.valueOf(2000000)).build();
To link a namespace and a mosaic, open a terminal window and run the following command.
Replace 7cdf3b117a3c40cc
with the mosaic identifier and foo
with the namespace name to be linked.
Did you find what you were looking for? Give us your feedback.