When I run the code then I fill the form the first time, the result is displayed well! but when I refresh the page or click on submit I get this error :
_http_outgoing.js:371 throw new Error('Can\'t set headers after they are sent.');
this is the code that I have written:
router.post('/send', function(req, res, next) {
var currentUser=req.body.currentUserAddress
var reciever= req.body.Addressedestinataire;
var amount = req.body.somme;
var data=[{"Spalte":amount}];
var s =JSON.stringify(data[0].Spalte);
var valueToken = JSON.parse(s);
mytoken.transfer.sendTransaction(currentUser,reciever,amount,{from :web3.eth.accounts[0],gas:5000000},function (error, result)
{
if(result)
{
let event = mytoken.Transfer();
event.watch(function(err, response)
{
if (err) {
console.log ("Error="+ err);
}
if (!err) {
let addressEvent= response.address;
let addressTo=response.args.to;
let addressFrom =response.args.from;
Transaction={addressFrom,addressTo,amount,date}
db.open(function(err, db) {
let collection = db.collection("Transaction");
collection.insertOne(Transaction, function(err, result1) {assert.equal(null, err);});
db.close();
});
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({addressEvent,addressFrom,addressTo,amount}));
}
});
}
else{
console.log(error);
}
});
});
`
via takampika
No comments:
Post a Comment