我有一个
smart contract
部署于
Kovan
,其中包含getter函数:
function getOrderStatus(uint _orderId) public view returns(bool shipped, bool arrived, bool payed) {
return (orders[_orderId].shipped, orders[_orderId].arrived, orders[_orderId].payed);
}
如果我通过Web3调用函数,我会在控制台上得到以下输出,这很好!:
Result {
'0': false,
'1': false,
'2': false,
shipped: false,
arrived: false,
payed: false }
但如果我试图通过
callback function
为了提供它,例如通过API,我在浏览器上得到了以下输出:
[object Object]
唯一的区别是
console.log(returnValue)
---GT;
callback(returnValue)
在以下代码末尾:
function getOrderStatus(_orderId, callback) {
contractABI.methods.getOrderStatus(_orderId).call()
.then(returnValue => callback(returnValue));
}
然后通过调用函数
Express
app.get('/api/getOrderStatus', function(req, res) {
orderId = req.query.orderId;
getOrderStatus(orderId, function(error, data) {
if (!error) {
res.send(data);
}
else
{
res.send(error);
}
});
});