Created
March 15, 2019 09:09
-
-
Save dgarcia360/c789b54bfb727c21f0ce89ee5380edf6 to your computer and use it in GitHub Desktop.
NEM2: Create and assign a namespace to an alias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Account, | |
AggregateTransaction, | |
AliasActionType, | |
AliasTransaction, | |
Deadline, | |
NetworkType, | |
RegisterNamespaceTransaction, | |
TransactionHttp, | |
UInt64 | |
} from "nem2-sdk"; | |
const namespaceName = 'foo'; | |
const nodeUrl = 'http://localhot:3000'; | |
const privateKey = ''; // replace with your private key | |
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST); | |
const registerNamespaceTx = RegisterNamespaceTransaction.createRootNamespace( | |
Deadline.create(), | |
namespaceName, | |
UInt64.fromUint(100000), | |
NetworkType.MIJIN_TEST | |
); | |
const registerAliasTx = AliasTransaction.createForAddress( | |
Deadline.create(), | |
AliasActionType.Link, | |
registerNamespaceTx.namespaceId, | |
account.address, | |
NetworkType.MIJIN_TEST); | |
const aggregateTransactionTx = AggregateTransaction.createComplete( | |
Deadline.create(), | |
[ | |
registerNamespaceTx.toAggregate(account.publicAccount), | |
registerAliasTx.toAggregate(account.publicAccount), | |
],NetworkType.MIJIN_TEST, []); | |
const signedTx = account.sign(aggregateTransactionTx); | |
const transactionHttp = new TransactionHttp(nodeUrl); | |
transactionHttp | |
.announce(signedTx) | |
.subscribe(x => console.log(x), err => console.log(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment