|
7 | 7 | * and then load this folder onto a HTTP WebServer (e.g.
|
8 | 8 | * using node-static or `python -mSimpleHTTPServer`).
|
9 | 9 | */
|
10 |
| -var Buffer = require('safe-buffer').Buffer // use for Node.js <4.5.0 |
11 |
| -var VM = require('../../index.js') |
| 10 | +const BN = require('bn.js') |
| 11 | +const VM = require('../../dist/index.js').default |
12 | 12 |
|
13 |
| -// create a new VM instance |
14 |
| -var vm = new VM() |
| 13 | +// Create a new VM instance |
| 14 | +// For explicity setting the HF use e.g. `new VM({ hardfork: 'petersburg' })` |
| 15 | +const vm = new VM() |
15 | 16 |
|
16 |
| -var code = '7f4e616d65526567000000000000000000000000000000000000000000000000003055307f4e616d6552656700000000000000000000000000000000000000000000000000557f436f6e666967000000000000000000000000000000000000000000000000000073661005d2720d855f1d9976f88bb10c1a3398c77f5573661005d2720d855f1d9976f88bb10c1a3398c77f7f436f6e6669670000000000000000000000000000000000000000000000000000553360455560df806100c56000396000f3007f726567697374657200000000000000000000000000000000000000000000000060003514156053576020355415603257005b335415603e5760003354555b6020353360006000a233602035556020353355005b60007f756e72656769737465720000000000000000000000000000000000000000000060003514156082575033545b1560995733335460006000a2600033545560003355005b60007f6b696c6c00000000000000000000000000000000000000000000000000000000600035141560cb575060455433145b1560d25733ff5b6000355460005260206000f3' |
| 17 | +const STOP = '00' |
| 18 | +const ADD = '01' |
| 19 | +const PUSH1 = '60' |
| 20 | + |
| 21 | +// Note that numbers added are hex values, so '20' would be '32' as decimal e.g. |
| 22 | +const code = [PUSH1, '03', PUSH1, '05', ADD, STOP] |
17 | 23 |
|
18 | 24 | vm.on('step', function (data) {
|
19 |
| - console.log(data.opcode.name) |
| 25 | + console.log(`Opcode: ${data.opcode.name}\tStack: ${data.stack}`) |
20 | 26 | })
|
21 | 27 |
|
22 | 28 | vm.runCode({
|
23 |
| - code: Buffer.from(code, 'hex'), |
24 |
| - gasLimit: Buffer.from('ffffffff', 'hex') |
| 29 | + code: Buffer.from(code.join(''), 'hex'), |
| 30 | + gasLimit: new BN(0xffff) |
25 | 31 | }, function (err, results) {
|
26 |
| - console.log('returned: ' + results.return.toString('hex')) |
27 |
| - console.log('gasUsed: ' + results.gasUsed.toString()) |
28 |
| - console.log(err) |
| 32 | + console.log('Returned : ' + results.return.toString('hex')) |
| 33 | + console.log('gasUsed : ' + results.gasUsed.toString()) |
| 34 | + console.log('Error : ' + err) |
29 | 35 | })
|
0 commit comments