-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path903_ns_mosaic_link_sample.html
132 lines (113 loc) · 4.22 KB
/
903_ns_mosaic_link_sample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="nem2-sdk-0.13.1.js"></script>
<script>$(function() {
const nem = require("/node_modules/nem2-sdk");
//覚え書き
//Alice Bob Carol Dave Ellen Frank
//https://hukusuke1007.github.io/nem2-wallet/
//https://catapult-test.opening-line.jp:3001/account/
//"generationHash":"453052FDC4EB23BF0D7280C103F7797133A633B68A81986165B76FCE248AB235"
//const NODE = 'https://catapult-test.opening-line.jp:3001';
//個人用
//"generationHash":"3125DF8F8C726660526886BAD6531A51A520845D984BE47943F9F844885CC7CA"
//private key: CD52E4CA8F6EC1ADBE4BEF392BAD666179A495F87CBC15176F30C8A82EBA90D6
//public key: 1BCA1267C0A13A6D78219463056B711683A4676A4C7F8883E64F7EC5291E6E51
//address (mijin-test): SADW6WXZVIUWIJ6RAWFSM4F4SJRUBRVOARXXIFSH
const NODE = 'https://catapult-test.opening-line.jp:3001';
const GENERATION_HASH = "453052FDC4EB23BF0D7280C103F7797133A633B68A81986165B76FCE248AB235";
const transactionHttp = new nem.TransactionHttp(NODE);
const alice = nem.Account.generateNewAccount(nem.NetworkType.MIJIN_TEST);
console.log(alice.address);
console.log(alice.privateKey);
const wsEndpoint = NODE.replace('https', 'wss');
const listener = new nem.Listener(wsEndpoint, WebSocket);
listener.open().then(() => {
listener
.unconfirmedAdded(alice.address)
.subscribe(
function(_){
console.log("--unconfirmed transaction--");
console.log(_);
},
err => console.error(err));
listener
.confirmed(alice.address)
.subscribe(
function(_){
listener.close();
buildMosaic();
},
err => console.error(err));
});
function buildMosaic(){
//ネームスペース作成
const namespaceTx = nem.RegisterNamespaceTransaction.createRootNamespace(
nem.Deadline.create(),
"xembook2",
nem.UInt64.fromUint(1),
nem.NetworkType.MIJIN_TEST
);
//モザイク作成
const nonce = nem.MosaicNonce.createRandom();
const mosaicDefTx = nem.MosaicDefinitionTransaction.create(
nem.Deadline.create(),
nonce,
nem.MosaicId.createFromNonce(nonce, alice.publicAccount),
nem.MosaicProperties.create({
supplyMutable: true,
transferable: true,
divisibility: 0,
duration: nem.UInt64.fromUint(1)
}),
nem.NetworkType.MIJIN_TEST
);
//モザイク変更
const mosaicChangeTx = nem.MosaicSupplyChangeTransaction.create(
nem.Deadline.create(),
mosaicDefTx.mosaicId,
nem.MosaicSupplyType.Increase,
nem.UInt64.fromUint(1000000),
nem.NetworkType.MIJIN_TEST
);
//モザイクとネームスペースのリンク
const mosaicAliasTx = nem.AliasTransaction.createForMosaic(
nem.Deadline.create(),
nem.AliasActionType.Link,
namespaceTx.namespaceId,
mosaicDefTx.mosaicId,
nem.NetworkType.MIJIN_TEST
);
const aggregateTransaction = nem.AggregateTransaction.createComplete(
nem.Deadline.create(),
[
namespaceTx.toAggregate(alice.publicAccount),
mosaicDefTx.toAggregate(alice.publicAccount),
mosaicChangeTx.toAggregate(alice.publicAccount),
mosaicAliasTx.toAggregate(alice.publicAccount),
],
nem.NetworkType.MIJIN_TEST,
[]
);
const signedTransaction = alice.sign(aggregateTransaction, GENERATION_HASH);
console.log(signedTransaction);
transactionHttp
.announce(signedTransaction)
.subscribe(x => {
$('#items2-ctrl ul').append('<li><a target="_blank" href="' + NODE + '/transaction/' + signedTransaction.hash + '/status">' + signedTransaction.hash + '</a></li>');
$('#items3-ctrl ul').append('<li><a target="_blank" href="' + NODE + '/transaction/' + signedTransaction.hash + '">' + signedTransaction.hash + '</a></li>');
console.log(x)
}, err => console.error(err));
}
})</script>
</head>
<body>
<h1>sample</h1>
<h3>state確認</h3><div id="items2-ctrl"><ul></ul></div>
<h3>confirmed確認</h3><div id="items3-ctrl"><ul></ul></div>
<div id="btn-ctrl"><button>送信</button></div>
</body>
</html>