Last active
May 11, 2018 06:20
-
-
Save lewisdaly/ae826239748f892516adb007d7ccb988 to your computer and use it in GitHub Desktop.
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
/** | |
* refer here: | |
* https://github.com/lewisdaly/iota_mam_examples/ | |
* for the rest of the code examples | |
*/ | |
declare var require: any | |
const Mam = require('../lib/mam.node.js'); | |
const IOTA = require('iota.lib.js'); | |
const express = require('express'); | |
var iota = new IOTA({ provider: `https://testnet140.tangle.works` }) | |
const app = express(); | |
// Initialise MAM State - PUBLIC | |
var mamState = Mam.init(iota) | |
// Publish to tangle | |
// ref: https://github.com/l3wi/mam.client.js/blob/master/example/publishPublic.js | |
const publish = async (packet: any) => { | |
// Create MAM Payload - STRING OF TRYTES | |
var message = Mam.create(mamState, packet) | |
// Save new mamState | |
mamState = message.state | |
// Attach the payload. | |
console.log('Root: ', message.root) | |
console.log('Address: ', message.address) | |
await Mam.attach(message.payload, message.address) | |
return message.root; | |
} | |
app.get('/', async (req: any, res: any) => { | |
const { message } = req.query; | |
console.log("publishing message:", message); | |
const root = await publish(message); | |
res.json({message, root}); | |
}); | |
app.listen(3000, () => console.log('Publisher listening on port 3000!')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment