Skip to content

Latest commit

 

History

History

javascript

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

EVMole JavaScript (WASM)

This directory contains API documentation and various examples (web page, nodejs, vite, webpack, parcel, esbuild) demonstrating how to use the EVMole library with its JavaScript (WASM) build in different environments and with various build tools.

The library is built with wasm-pack. To simplify usage, we provide a default entry point with await init(), which should work in all modern browsers and bundlers.

Usage

Web page

You can load evmole directly in a web page using a script module. Here's how to do it:

<div id="selectors"></div>

<script type="module">
import { functionSelectors } from 'https://cdn.jsdelivr.net/npm/evmole@0.4.1/dist/evmole.mjs';

const bytecode = '0x6080...'; // Replace with actual bytecode
document.getElementById('selectors').textContent = functionSelectors(bytecode);
</script>

Node.js

You can use EVMole with both import and require syntax:

Vite

Set target: esnext in vite.config.js to support Top Level Await, required for default EVMole import:

build: {
  target: 'esnext'
}

After that, import and use EVMole as usual.

If you can't use esnext, see the No Top Level Await section.

Webpack

Set asyncWebAssembly: true in webpack.config.js:

experiments: {
  asyncWebAssembly: true,
}

After that, import and use EVMole as usual.

Parcel

Parcel can't work with Top Level Await, so you need to manually call init after import. See examples with:

You can read more about this in parcel resolver documentation

esbuild

Pass --format=esm and --loader:.wasm=file to esbuild. Find the full command in package.json

After that, import and use EVMole as usual.

No Top Level Await

If you can't use Top Level Await, you can import EVMole as:

import init, { functionSelectors } from 'evmole/no_tla`
// or: from 'evmole/dist/evmole.js' (supported, but not recommended)

After that, you can use it as:

const bytecode = '0x6080...'; // Replace with actual bytecode
async function main() {
  await init();
  console.log(functionSelectors(bytecode));
}
main()

or

const bytecode = '0x6080...'; // Replace with actual bytecode
init().then() => {
  console.log(functionSelectors(bytecode));
}

See full example without Top Level Await in Parcel example

API

functionSelectors(code, gas_limit)Array.<string>

Extracts function selectors from the given bytecode.

functionArguments(code, selector, gas_limit)string

Extracts function arguments for a given selector from the bytecode.

functionStateMutability(code, selector, gas_limit)string

Extracts function state mutability for a given selector from the bytecode.

functionSelectors(code, gas_limit) ⇒ Array.<string>

Extracts function selectors from the given bytecode.

Returns: Array.<string> - Function selectors as a hex strings

Param Type Description
code string Runtime bytecode as a hex string
gas_limit number Maximum allowed gas usage; set to 0 to use defaults

functionArguments(code, selector, gas_limit) ⇒ string

Extracts function arguments for a given selector from the bytecode.

Returns: string - Function arguments (ex: 'uint32,address')

Param Type Description
code string Runtime bytecode as a hex string
selector string Function selector as a hex string
gas_limit number Maximum allowed gas usage; set to 0 to use defaults

functionStateMutability(code, selector, gas_limit) ⇒ string

Extracts function state mutability for a given selector from the bytecode.

Returns: string - payable | nonpayable | view | pure

Param Type Description
code string Runtime bytecode as a hex string
selector string Function selector as a hex string
gas_limit number Maximum allowed gas usage; set to 0 to use defaults