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.
You can load evmole directly in a web page using a script module. Here's how to do it:
<div id="info"></div>
<script type="module">
import { contractInfo } from 'https://cdn.jsdelivr.net/npm/evmole@0.6.0/dist/evmole.mjs';
const bytecode = '0x6080...'; // Replace with actual bytecode
document.getElementById('info').textContent = contractInfo(bytecode, {selectors: true, arguments: true, stateMutability: true});
</script>
You can use EVMole with both import and require syntax:
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.
Set asyncWebAssembly: true
in webpack.config.js:
experiments: {
asyncWebAssembly: true,
}
After that, import and use EVMole as usual.
Parcel can't work with Top Level Await, so you need to manually call init after import. See examples with:
- default parcel installation
- example with
"packageExports": true
set in package.json
You can read more about this in parcel resolver documentation
Pass --format=esm
and --loader:.wasm=file
to esbuild.
Find the full command in package.json
After that, import and use EVMole as usual.
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(contractInfo(bytecode, {selectors: true}));
}
main()
or
const bytecode = '0x6080...'; // Replace with actual bytecode
init().then() => {
console.log(contractInfo(bytecode, {selectors: true}));
}
See full example without Top Level Await in Parcel example
contractInfo(code, args) ⇒ Contract
Analyzes contract bytecode and returns contract information based on specified options.
Kind: global function
Returns: Contract
- Analyzed contract information
Param | Type | Description |
---|---|---|
code | string |
Runtime bytecode as a hex string |
args | Object |
Configuration options for the analysis |
[args.selectors] | boolean |
When true, includes function selectors in the output |
[args.arguments] | boolean |
When true, includes function arguments information |
[args.state_mutability] | boolean |
When true, includes state mutability information for functions |
[args.storage] | boolean |
When true, includes contract storage layout information |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[functions] | Array.<ContractFunction> |
Array of functions found in the contract. Not present if no functions were extracted |
[storage] | Array.<StorageRecord> |
Array of storage records found in the contract. Not present if storage layout was not extracted |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
selector | string |
Function selector as a 4-byte hex string without '0x' prefix (e.g., 'aabbccdd') |
bytecode_offset | number |
Starting byte offset within the EVM bytecode for the function body |
[arguments] | string |
Function argument types in canonical format (e.g., 'uint256,address[]'). Not present if arguments were not extracted |
[state_mutability] | string |
Function's state mutability ("pure", "view", "payable", or "nonpayable"). Not present if state mutability were not extracted |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
slot | string |
Storage slot number as a hex string (e.g., '0', '1b') |
offset | number |
Byte offset within the storage slot (0-31) |
type | string |
Variable type (e.g., 'uint256', 'mapping(address => uint256)', 'bytes32') |
reads | Array.<string> |
Array of function selectors that read from this storage location |
writes | Array.<string> |
Array of function selectors that write to this storage location |
Please use contractInfo(code, {selectors: true}) instead
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 |
Please use contractInfo(code, {arguments: true}) instead
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 |
Please use contractInfo(code, {stateMutability: true}) instead
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 |