【发布时间】:2018-06-12 19:10:34
【问题描述】:
我想返回一个包含提供者对象的 web3 实例。我想将该对象返回给 UI,以便我可以在 UI 中使用该 web3 实例。这有可能实现吗? 我尝试将 web3 转换为 JSON.stringify(web3) 但抛出错误无法将圆形对象转换为字符串。
这是我的 nodejs 代码
const provider = new HDWalletProvider(
'dress steel phrase album average asd dd room exile web eree cause',
'https://rinkeby.infura.io/I7P2ErGiQjuq4jNp41OE',
);
web3 = new Web3(provider);
我想像这样将 web3 实例从节点返回到 UI
app.get('/getWeb3', async (req, res) => {
console.log('web3 instance', web3);
res.json( JSON.stringify(web3)); // this is throwing error.
})
我曾尝试使用第三方库将对象转换为 json,例如 warp 库,但仍然遇到问题。任何建议都会对我有所帮助。谢谢
【问题讨论】:
-
当你尝试
stringify对象时出现什么错误?
标签: javascript node.js web3js