当我尝试与 meteor 应用程序的服务器端的合约进行交互时,我收到错误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 行引发错误。如果我在客户端运行相同的代码,我就不会遇到问题。
我遇到了同样的问题。我ethereum:web3
NPM 包中使用web3@0.20.1
而不是 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';
我没有使用过 web3,但我怀疑它正在利用 XMLHttpRequest
,它只存在于浏览器中。尝试在服务器上获取类似物。我会从这个开始:XMLhttpRequest