【问题标题】:TypeError: XMLHttpRequest is not a function when using web3 on meteor server sideTypeError:在流星服务器端使用 web3 时,XMLHttpRequest 不是函数
【发布时间】:2017-10-23 07:17:50
【问题描述】:

当我尝试与我的流星应用程序服务器端的合同交互时,我收到错误 TypeError: XMLHttpRequest is not a function

web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))

var cocontract = web3.eth.contract(abi).at(address);
var name = (cocontract.name())

第 3 行引发了错误。如果我在客户端运行相同的代码,我不会遇到问题。

【问题讨论】:

    标签: meteor server-side ethereum web3js


    【解决方案1】:

    我没有使用过 web3,但我怀疑它利用了 XMLHttpRequest,它只存在于浏览器中。尝试在服务器上获得类似物。我将从这个开始: xmlhttprequest

    【讨论】:

    • 我相信web3自带xmlhttprequest节点模块
    【解决方案2】:

    我遇到了同样的问题。取而代之的是ethereum:web3 Meteor 包,我使用了web3@0.20.1 NPM 包,它工作正常(Meteor 版本 1.5.1)。 所以,如果你使用ethereum:web3,你可能需要运行:

    meteor remove ethereum:web3
    meteor npm install web3@0.20.1 --save
    

    替换

    import { Web3 } from 'meteor/ethereum:web3';
    

    import Web3 from 'web3';
    

    【讨论】:

      猜你喜欢
      • 2015-05-23
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-16
      相关资源
      最近更新 更多