-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
58 lines (52 loc) · 4.09 KB
/
index.js
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
const IOTA = require('iota.lib.js');
const CCurl = require('ccurl.interface.js');
const {
promisify
} = require('util');
// not really used as we don't do any TX with value changes.
const MWM = 15;
let seed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9ABCDEFGHIJKLMNOPQRSTUVWXYZ9';
let targetAddress = '99999999999999999999999999999999999999999999999999999999999999999RUUVI9LOVES9IOTA';
let targetTag = 'ALL9THE9TAGGING9YOULL9NEED9';
let message = 'HSVKSZBJFAI9OUUXZSAYVPHENMYSMDOTXSVUISVGWN9DVUBYTNXCFQK9AAAWHFIBHLPRHXIXPX9HUCRUCILCKVZGYBOJEHGJFA9YFGIHNS99ILCOOKWV9FVLGVKCMPVPDZFXTKOBGVKXVTDLOVYCEYTTGRXVWBVFKFXHWQGQSQNESOEAMSSVBCOQVCWKEHHONFQKIBEHXYBNYIYBBXFZNBLGVHXPJTPSRB9FSVGBNVHADGGLKLIIARULVV9ALN99QTS9JUGTTFCNCXEGUZIUFWMXGYVK9YDKFVXMHDRNHRINXKKCIELUAGIDFUIANFNMSZQJGDYDZDQDURRLXHLYCDLFBRZYTQDJZUVAWXKWHGJHDUHETGNDSP9ABBIU9PAGZMLJKNCXTCZSQJXRBCEJ9PQPFLYKLUMEUGNOOTUFLABBBAPEWTWKTAMLMARRLSYRCWSYZRITTRLLLBP9XTRCFMJYYIZSZEVSXTVBFLAOENMPPKWZOUEBIORBVIWXVCTNKRYJMAXTKKMUR9IJDWEVHUBUJMQZIMAFSGZAIGHWHMOOLLINHNVJSIAEDUAO9ZZRABQ9AFRMEE9GLXHSMZIVZIZSSPHTYDKBFAMCWOPOE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LCOM99BTBKDXMXRJOZSYXLSXDQQDEZ9NPCBJDVHARHHJCPGZTMJAV9PJSAEX9YILZBKUVAVNGFRWETNNFMRJYFXSOAOT9KDXTHAWABGZLWYLZVGABLSWUQGLAVWOFUAVQNAGLQWLGXCUSYXTWWCFWDHERSNXGFHKOEXWMBXBYASSBZGNVBOOPAWYBLDQMBXVBVARTDQPYCZLKWIVVJFLVINRDIIKLGEDWSLMOVLSYGDWZIAYRUPKJATMWBTJUADLJUJXI9XVXF9VXWGIIMEIESHZSCGUNAZBJFUXYJQ9KMBZVGJCOWOXGMTA9V9HI9FXILRKYQIFIGAGGCMYAQU9WKIHSOKKRFMWQZBGHHX9UARCSZJGLNGNMRNVBYMGXVRCSLRKMBWIWJVVWAHKAFQPJWOOMKQDOIKONZXKPZ9FXPNZUVT9ZVIQCBRECOQRZJPPYWQAPEWNVMSS9BPPOXCSOZFGP9NNRLQWEJWBKRXRDJAUGUCLZIVYYIPEH9YHR9VGNLFLTJQVYWXHVFKFFPANVMMKNUNUUFDLAVPQNNSGFGKID9CUQVMWWPBAWN9SPSTFDGUSYSCWTNCMNVPPJFITVKTAIQNHWPOKXCTJGTMPPFFBUIQIHPSOYPPZXLUKKCSGFQLRJLR9GOZIALKBIJOLTKDOTBHUSGMYM9WRPBUK9GIIJKWNTJLPDAXZYCKGLCRLRSVHTYYJNHOQEUVRFDRNJISJEEPAJANACSFPDOHGVNCSSGXAAHS9CYDYQBZOQZCFDOHBFDEVGAIF';
// sample MAM payload.
// construct iota.lib.js instance
let iota = new IOTA({
'host': 'http://service.iotasupport.com',
'port': 14265
});
const PCCurl = promisify(CCurl);
const PprepareTransfers = promisify(iota.api.prepareTransfers);
const PgetTransactionsToApprove = async depth => {
return new Promise((resolve, reject) => {
iota.api.getTransactionsToApprove(depth, function(err, suc) {
if (err != undefined) {
reject(err);
} else {
resolve(suc);
}
});
});
};
const PbroadcastTransactions = async trytes => {
return new Promise((resolve, reject) => {
iota.api.broadcastTransactions(trytes, function(err, suc) {
if (err != undefined) {
reject(err);
} else {
resolve(suc);
}
});
});
};
PprepareTransfers(seed, [{
address: targetAddress,
value: 0,
message: message,
tag: targetTag
}]).then(transactions => {
return PgetTransactionsToApprove(5).then(toApprove => {
return PCCurl(toApprove.trunkTransaction, toApprove.branchTransaction, MWM, transactions);
});
}).then(bundle => PbroadcastTransactions(bundle))
.then(ret => console.log(ret));