https://github.com/ethereumjs/ethereumjs-vm/tree/master/examples/run-transactions-simple

prerequisite先决条件

$ npm install -g browserify http-server

然后还要将package.json中的模块安装了:

npm install

Instruction

Run command

$ browserify index.js -o bundle.js

运行成功后生成:

Then host this folder in a web server

$ http-server

终端:

userdeMacBook-Pro:run-transactions-simple user$ http-server
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://192.168.1.102:8080
Hit CTRL-C to stop the server
[Sat Dec :: GMT+ (中国标准时间)] "GET /" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15"
[Sat Dec :: GMT+ (中国标准时间)] "GET /bundle.js" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15"

open http://localhost:8080 in a browser and check the result in web console.

页面运行情况:

查看代码到底做了什么:

index.js

/*
* Example - Running code on an ethereum-vm
*
*
* To run this example in the browser, bundle this file
* with browserify using `browserify index.js -o bundle.js`
* and then load this folder onto a HTTP WebServer (e.g.
* using node-static or `python -mSimpleHTTPServer`).
*/
var Buffer = require('safe-buffer').Buffer // use for Node.js <4.5.0
var VM = require('../../index.js') // create a new VM instance
var vm = new VM() var code = '7f4e616d65526567000000000000000000000000000000000000000000000000003055307f4e616d6552656700000000000000000000000000000000000000000000000000557f436f6e666967000000000000000000000000000000000000000000000000000073661005d2720d855f1d9976f88bb10c1a3398c77f5573661005d2720d855f1d9976f88bb10c1a3398c77f7f436f6e6669670000000000000000000000000000000000000000000000000000553360455560df806100c56000396000f3007f726567697374657200000000000000000000000000000000000000000000000060003514156053576020355415603257005b335415603e5760003354555b6020353360006000a233602035556020353355005b60007f756e72656769737465720000000000000000000000000000000000000000000060003514156082575033545b1560995733335460006000a2600033545560003355005b60007f6b696c6c00000000000000000000000000000000000000000000000000000000600035141560cb575060455433145b1560d25733ff5b6000355460005260206000f3' vm.on('step', function (data) {
console.log(data.opcode.name)
}) vm.runCode({
code: Buffer.from(code, 'hex'),
gasLimit: Buffer.from('ffffffff', 'hex')
}, function (err, results) {
console.log('returned: ' + results.return.toString('hex'))
console.log('gasUsed: ' + results.gasUsed.toString())
console.log(err)
})

其实就是在vm上运行了一段代码

index.html

<script src='/bundle.js'></script>

ethereumjs-vm/examples/run-transactions-simple的更多相关文章

  1. Qt Examples Qt实例汇总

    ActiveQt Examples Using ActiveX from Qt applications. Animation Framework Examples Doing animations ...

  2. ethereumjs/browser-builds

    https://github.com/ethereumjs/browser-builds ethereumjs - Browser Builds This repository contains br ...

  3. ethereumjs/ethereumjs-vm-4-tests

    根据代码发现还要了解的模块有: ethereumjs/merkle-patricia-tree -对应数据存储的数据结构 ethereumjs-blockchain —— 区块链 ethereumjs ...

  4. Extended VM Disk In VirtualBox or VMware (虚拟机磁盘扩容)

    First, Clean VM all snapshot, and poweroff your VM. vmdk: vmware-vdiskmanager -x 16GB myDisk.vmdk vd ...

  5. 学习 java命令

    依稀记得自己第一次编译*.java文件,第一次运行*.class文件.但是六七年过去了,现在运行java写的程序更多的是用tomcat这种web容器.最近有个小需求,写一个监控zookeeper集群的 ...

  6. Java Annotations: Explored & Explained--转载

    原文地址:http://www.javacodegeeks.com/2012/08/java-annotations-explored-explained.html One of the many w ...

  7. ormlite 文档

    目录[-] A Fast, Simple, Typed ORM for .NET Download 8 flavours of OrmLite is on NuGet: Docs and Downlo ...

  8. C++开源库集合

    | Main | Site Index | Download | mimetic A free/GPL C++ MIME Library mimetic is a free/GPL Email lib ...

  9. mininet安装,使用

    http://mininet.org/download/ http://sdnhub.cn/index.php/mininet-walkthrough-chinese/ --------------- ...

  10. Java programming language compiler

    https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html\ javac - Java programming l ...

随机推荐

  1. Spring 中的Enum HttpStatus 及HTTP状态码

    官方API https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/HttpStatus.htm ...

  2. 撩课-Java每天5道面试题第12天

    91.如何提升数据查询的效率? 1.首先检查表的结构是否合理, 因为采用多表查询的时候, 看主外键的引用关系是否适当. 如果不适当则重新设置表结构. 如果是应用中的系统, 则不需要更改表的字段, 只更 ...

  3. Spring Boot学习笔记(三)实现热部署

    pom文件中添加如下依赖即可 <dependency> <groupId>org.springframework.boot</groupId> <artifa ...

  4. JavaScript自定义字符串格式化

    在JS中没有字符串拼接的方法,如过要使用怎么办呢?这时我们可以通过字符串的prototype可以自定义方法. <script> String.prototype.format = func ...

  5. Uncaught TypeError: _react2.default.createContext is not a function

    question is caused by react version, update your react version, it will be ok. use "npm update ...

  6. Mac里用终端ssh远程连接Centos服务器

    在mac终端下输入 ssh -l root *.*.*.* 就可以远程连接Centos服务器了,端口没变还是:22 如果改变端口用下面方法输入: ssh -p 448(你改变的端口) -l root( ...

  7. 001profile条件化创建bean

    01.类级别条件创建 @Configuration @Profile("dev") public class Aclass{}---->影响整个类,包括类的注解.开发环境,类 ...

  8. 自学git心得-3

    转眼到第三节了,我们进入分支管理. git领域里的分支可以理解为一个有安全保障的临时仓库,有时我们新修改了代码,突然发现有bug需要回到之前的版本,有时我们开发到一半,突然要出去一趟,如何安全保存当前 ...

  9. Python3.x urlib包

    在Python3.x中,我们可以使用urlib这个组件抓取网页,urllib是一个URL处理包,这个包中集合了一些处理URL的模块,如下: 1.urllib.request模块是用来打开和读取URLs ...

  10. Java实例---简单的超市管理系统

    代码分析 Customer.java package test; public class Customer { private String name; private int customerTy ...