Building EVM Modules to replace JS Dependencies for Web3 Apps
Replacing Javascript Module Dependencies and Migrating to EVM Modules for a More Modular Web3 Ecosystem
Web3 decentralized applications can (and should) be using minimal JS. Node package manager (NPM) and Javascript in general pose open up a huge supply chain attack vector.
The MetaMask team is hard at working solving this problem 👇
I want to make the case for why decentralized applications, should replace JS modules for EVM modules. In certain situations.
The JS modules should probably meet the following criteria though:
A) Replicate EVM operations using JS abstractions
B) Communicating with JSON RPC endpoints to access pure functions
That’s it. If you’re using JS modules to replicate EVM operations (likely off-chain calculations) or hitting JsonRPC API endpoints to utilize smart contracts like an API then it might be time to think about what’s next.
If the JS module fits these criteria then it’s a likely candidate for becoming an EVM module and thus minimizing dependencies on centralized systems.
What is an EVM module?
An EVM module starts with a Smart Contract API.
A Smart Contract API is an individual smart contract (chain agnostic) which sole purpose is to expose only pure functions. The smart contract DOES NOT contain any references to state or external resources.
The smart contract does not even need to know it lives on a blockchain.
Even better! It doesn’t need to live on a blockchain if simulate the EVM.
The Smart Contract API sole purpose is performing computations.
Why is this important?
The Web3 ecosystem can remove significant dependencies like NPM and other insecure JS delivery systems for essential off-chain calculations and computations.
Plus, the Web3 ecosystem in general can be more modular.
How To Replace JS Modules with EVM Modules
PoolTogether has a JS module that fits the criteria.
“Replicate EVM operations using JS abstractions”
Let’s use The PoolTogether V4 Utils JS Module as an example for conversion.
Github: https://github.com/pooltogether/v4-utils-js
NPM: https://www.npmjs.com/package/@pooltogether/v4-utils-js
For context the Utilities module is responsible for off-chain calculations and computations. It’s used to calculate a Depositor’s winning pick indices in the PoolTogether V4 protocol.
The module functions have no side effects and thus are pure similar to the Smart Contract functions we need to recreate.
Get Kames Geraghty’s stories in your inbox
Join Medium for free to get updates from this writer.
To request state, which is passed into the utility functions, the PoolTogether V4 Client JS module is used.
Creating a clear separation between data fetching and data parsing.
Since the Utilities module is pure we can construct an EVM module to replace the JS module.
The above code snippet replicates the calculateCardinality calculations function exported from the JS module. Even including parseUnits which is a reference to the ethers-js utility library :)
Using the Smart Contract code snippet we can start to make an EVM Module.
The contract is only exposing pure functions.
It can be considered a Smart Contract API.
Current Decentralized Applications
Let’s imagine current decentralized applications as a very basic connection between Browser and Ethereum Virtual Machine environments.
The environments don’t share any code. And oftentimes JS modules will replicate EVM operations for off-chain calculations.
But… this is cumbersome and requires multiple languages.
Future Decentralized Applications
The future of optimized decentralized applications could look much different.
- Code sharing between EVM and Browser to increase modularity
- More secure browser modules (unalterable WASM files)
So What Is an EVM Module… Exactly?
The EVM Module concept is still being developed, but a minimum it will need.
- Smart Contract API (stateless contract with public/pure functions)
- EVM <> WASM Compiling
- Generated EVM Module JS/WASM Messaging Plugin
EVM Module can help bridge the gap between Browser and Web3.
Empowering JS Developers to create composable ecosystem modules.
Empowering EVM Developers to create secure browser modules.









