繁体   English   中英

使用javascript,solidity和html时Web3模块未定义的错误

[英]Web3 module undefined error while using javascript, solidity and html

我正在尝试为我的固定合同建立UI。 到目前为止,文件如下:

index.html : which contains ui part(tables, buttons, etc)

    server.js:

        var express = require('express');
        var app = express();
        app.use('/', express.static(__dirname + '/'));
        app.listen(8080,() => console.log('Example app listening on port 8080!'));

    index.js:
    web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    abi = JSON.parse('[{"constant":true,"inputs"......');
    // In your nodejs console, execute contractInstance.address to get the address at which the contract is deployed and change the line below to use your deployed address
    VotingContract = web3.eth.contract(abi);
    contractInstance = VotingContract.at('deployed address name');
    //rest of the functions required..

Solidity file: this contains the contract that will deployed on the blockchain

当我在本地主机上运行服务器时,出现错误,提示未定义web3。 谁能帮我这个?? 谢谢!!!

我找到了答案。 我只需要在我的server.js文件中包含web3:

var express = require('express');
var Web3 = require('web3');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM