I am an experienced C#/Angular developer learning node.js and teh multichain API. I am trying to simply POST a 'key' and 'data' to one of my streams.
This is the library I am using: https://github.com/scoin/multichain-node
My code is returning errors. This is the error it returns:
C:\Dev\learning\nodeJS_Learning\PoE-API\poe\poe.API\node_modules\express\lib\response.js:1075
: JSON.stringify(value);
^
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at stringify (C:\Dev\learning\nodeJS_Learning\PoE-API\poe\poe.API\node_modules\express\lib\response.js:1075:12)
at ServerResponse.json (C:\Dev\learning\nodeJS_Learning\PoE-API\poe\poe.API\node_modules\express\lib\response.js:24
9:14)
at ServerResponse.send (C:\Dev\learning\nodeJS_Learning\PoE-API\poe\poe.API\node_modules\express\lib\response.js:15
8:21)
at multichain.publish (C:\Dev\learning\nodeJS_Learning\PoE-API\poe\poe.API\routes\publish.js:31:44)
at client.call (C:\Dev\learning\nodeJS_Learning\PoE-API\poe\poe.API\node_modules\multichain-node\lib\rpccall.js:40:
17)
at IncomingMessage.res.on (C:\Dev\learning\nodeJS_Learning\PoE-API\poe\poe.API\node_modules\multichain-node\lib\cli
ent.js:60:32)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
This is my API Call using Node.JS
var multichain = require("multichain-node")({
port: "6448",
host: "45.63.60.176",
user: "multichainrpc",
pass: "xxxxxxxxxx"
});
app.post('/publish/', function (req, res) {
var keyToPublish = req.body.key;
var dataToPublish = req.body.data;
var streamName = "poe";
if ((keyToPublish == undefined) || (dataToPublish == undefined)) {
return res.send(400, "Please insert a data and key in the POST body to publish.");
} else {
var dataToadd = new Buffer(dataToPublish).toString("hex");
console.log(dataToPublish);
console.log(keyToPublish);
multichain.publish({
stream: "poe",
key: "testKey-01",
data: dataToadd
},
(err) => {
// console.log(res);
return res.status(200).send(res);
});
};
});
Can anyone help me and point me in the right direction?
Thanks!