我嘗試包括此build,在我的瀏覽器JS用Node.js的,這裏是我的服務器代碼:的ReferenceError用Node.js和受Browserify
var fs = require("fs");
var http = require("http");
var url = require("url");
http.createServer(function (request, response) {
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname + " received.");
response.writeHead(200);
if(pathname == "/") {
html = fs.readFileSync("views/index.html", "utf8");
response.write(html);
} else if (pathname == "/ethereumjs-all.js") {
script = fs.readFileSync("views/ethereumjs-all.js", "utf8");
response.write(script);
}
response.end();
}).listen(8000);
console.log("Listening to server on 8000...");
這裏是index.html
內容:
<html>
<head>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="/ethereumjs-all.js"></script>
<script>
$(document).ready(function() {
var tx = new Transaction()
...
}); // document.ready
</script>
</head>
<body></body>
</html>
但是,在瀏覽器控制檯中,我收到錯誤ReferenceError: Transaction is not defined
庫應該有Transaction
類定義。那麼我使用browserify是否錯誤?
感謝您的幫助!
凡定義的'Transaction'構造? –
@DaveGomez實際上我不確定,但代碼在服務器端工作..現在我檢查了[ethereumjs-tx.js](https://github.com/ethereumjs/browser-builds/blob/master/ dist/ethereumjs-tx.js#L8389),第8389行看起來像構造函數,但是再一次,我在JS中不太流利,所以我不確定這是否是我們需要的。 – jeff