ethereumjs/browser-builds
https://github.com/ethereumjs/browser-builds
ethereumjs - Browser Builds
This repository contains browser builds of the following ethereumjs
libraries:
這個儲存庫包含以下ethereumjs庫的瀏覽器構建(其實就是將下面的ethereumjs庫構造成瀏覽器能夠使用的js檔案形式)
- ethereumjs-vm
- ethereumjs-tx
- ethereumjs-wallet
- ethereumjs-wallet-hd
- ethereumjs-wallet-thirdparty
- ethereumjs-icap
- ethereumjs-abi
- ethereumjs-all
They are built using browserify with a known set of working dependencies.
使用帶著具有一組已知的工作依賴項的browserify來構建
For every library/build collection there is a larger plain source version also including the source mappings (e.g. ethereumjs-vm-x.x.x.js
ethereumjs-vm-x.x.x.min.js
).
這裡對每個庫/構建收集有一個更大的包含資源對映(比如ethereumjs-vm-x.x.x.js
) 的純資源版本,以及在生產時使用的簡化版本 (比如
ethereumjs-vm-x.x.x.min.js
)
Note注意:
This repository was just lately (October 2017) revived. Currently all builds are considered experimental
這個儲存庫最近(2017/10)才恢復使用。目前,從API的穩定性、功能和安全性來看,所有構建都是實驗性的
Usage使用
In your web application, include only one of the builds from the dist
directory. All exports will be available under the global ethereumjs
.
在你的web應用中,只包含來自dist目錄之一的構建。在全域性變數ethereumjs
下,所有的構建都是可用的
Note: all packages expect ECMAScript 6 (ES6) as a minimum environment. From browsers lacking ES6 support, please use a shim (like es6-shim) before including any of the builds from this repo.
注意:所有包都期待使用 ECMAScript 6 (ES6) 作為最小的環境。如果瀏覽器缺少ES6支援,從該儲存庫中包含任何構建之前,請使用shim(like es6-shim)
Examples例子
Examples for usage of the browser builds can be found in the examples
directory:
vm.html
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>EthereumJS VM - Browser Example</title> </head> <body> <script src="../dist/ethereumjs-vm/ethereumjs-vm-2.3.1.js"></script> <script> var vm = new ethereumjs.VM() var code = '7f4e616d65526567000000000000000000000000000000000000000000000000003055307f4e616d6552656700000000000000000000000000000000000000000000000000557f436f6e666967000000000000000000000000000000000000000000000000000073661005d2720d855f1d9976f88bb10c1a3398c77f5573661005d2720d855f1d9976f88bb10c1a3398c77f7f436f6e6669670000000000000000000000000000000000000000000000000000553360455560df806100c56000396000f3007f726567697374657200000000000000000000000000000000000000000000000060003514156053576020355415603257005b335415603e5760003354555b6020353360006000a233602035556020353355005b60007f756e72656769737465720000000000000000000000000000000000000000000060003514156082575033545b1560995733335460006000a2600033545560003355005b60007f6b696c6c00000000000000000000000000000000000000000000000000000000600035141560cb575060455433145b1560d25733ff5b6000355460005260206000f3' console.log('Code to be run in the VM:') console.log(code) vm.on('step', function (data) { console.log(data.opcode.name) }) vm.runCode({ code: ethereumjs.Buffer.Buffer.from(code, 'hex'), gasLimit: ethereumjs.Buffer.Buffer.from('ffffffff', 'hex') }, function (err, results) { console.log('returned: ' + results.return.toString('hex')) console.log('gasUsed: ' + results.gasUsed.toString()) console.log(err) }) </script> </body> </html>
Start an http-server from the main directory of the repository to run the examples in the browser.
從儲存庫的主目錄開啟 http-server去在瀏覽器中執行該例子
Build構建
Builds are done using the .js
exports
compilation files from the src/ directory and using the build.js script from the main directory to create the build in the dist/ folder.
構建的完成需要先從src/資料夾中
使用.js
輸出編譯檔案,然後使用來自主目錄的build.js指令碼在dist/資料夾中建立構建
Version numbers for the builds are directly extracted from the versions installed in the local node_modules
folder.
構建的版本數目直接從安裝在本地的node_modules
資料夾的版本中抽取出。
For creating new builds:為了建立新的構建
- Change
package.json
to require desired/up-to-date versions of the libraries 改變package.json
去獲取想要的/最新版本的庫
package.json
{ "private": true, "name": "browser-builds", "version": "0.0.0", "description": "Browser builds of ethereumjs libraries.", "scripts": { "build": "node build.js" }, "repository": { "type": "git", "url": "git+https://github.com/ethereumjs/browser-builds.git" }, "keywords": [ "ethereum", "browser" ], "author": "Alex Beregszaszi <[email protected]>", "license": "MIT", "bugs": { "url": "https://github.com/ethereumjs/browser-builds/issues" }, "homepage": "https://github.com/ethereumjs/browser-builds#readme", "dependencies": {//這裡寫了所有的庫,你可以根據你自己的需求進行刪減,並更改相應的版本 "ethereumjs-abi": "^0.6.2", "ethereumjs-icap": "^0.3.1", "ethereumjs-tx": "^1.3.1", "ethereumjs-units": "^0.2.0", "ethereumjs-vm": "^2.3.0", "ethereumjs-wallet": "^0.6.0" }, "devDependencies": { "babel-preset-env": "^1.7.0", "babel-preset-react": "^6.24.1", "babelify": "^7.3.0", "browserify": "^14.4.0", "uglifyify": "^4.0.4" } }
2.Reinstall/update local node_modules
packages 重新安裝/更新本地node_modules
包
執行npm install
3.Run npm run build
to generate new set of builds 執行npm run build
命令去生成新構建集
返回:
userdeMBP:browser-builds-master user$ npm run build > [email protected]0.0.0 build /Users/user/browser-builds-master > node build.js ***ethereumjs-all*** Creating debug version package dist/ethereumjs-all/ethereumjs-all-2018-12-07.js Creating minified package dist/ethereumjs-all/ethereumjs-all-2018-12-07.min.js ***ethereumjs-vm*** Creating debug version package dist/ethereumjs-vm/ethereumjs-vm-2.5.0.js Creating minified package dist/ethereumjs-vm/ethereumjs-vm-2.5.0.min.js ***ethereumjs-tx*** Creating debug version package dist/ethereumjs-tx/ethereumjs-tx-1.3.7.js Creating minified package dist/ethereumjs-tx/ethereumjs-tx-1.3.7.min.js ***ethereumjs-icap*** Omitting debug version package dist/ethereumjs-icap/ethereumjs-icap-0.3.1.js (file exists) Omitting minified package dist/ethereumjs-icap/ethereumjs-icap-0.3.1.min.js (file exists) ***ethereumjs-wallet*** Creating debug version package dist/ethereumjs-wallet/ethereumjs-wallet-0.6.2.js Creating minified package dist/ethereumjs-wallet/ethereumjs-wallet-0.6.2.min.js ***ethereumjs-wallet-hd*** Creating debug version package dist/ethereumjs-wallet-hd/ethereumjs-wallet-hd-0.6.2.js ***ethereumjs-abi*** Omitting debug version package dist/ethereumjs-abi/ethereumjs-abi-0.6.5.js (file exists) Omitting minified package dist/ethereumjs-abi/ethereumjs-abi-0.6.5.min.js (file exists) Creating minified package dist/ethereumjs-wallet-hd/ethereumjs-wallet-hd-0.6.2.min.js ***ethereumjs-wallet-thirdparty*** Creating debug version package dist/ethereumjs-wallet-thirdparty/ethereumjs-wallet-thirdparty-0.6.2.js Creating minified package dist/ethereumjs-wallet-thirdparty/ethereumjs-wallet-thirdparty-0.6.2.min.js
然後你的dist資料夾下就會得到你想要的構建了,然後你就能夠在頁面端使用這些構建了,就像上面的例子一樣