Created
July 26, 2025 13:48
-
-
Save bkpleb/202b2ca7234bbce286b50fdbf6d57063 to your computer and use it in GitHub Desktop.
A function selector calculator that helps identify different Account Abstraction (AA) implementations by their unique function signatures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // calculate_function_selector.js | |
| import { keccak256, toUtf8Bytes } from 'ethers'; | |
| function calculateFunctionSelector(functionSignature: string): string { | |
| const fullHash = keccak256(toUtf8Bytes(functionSignature)); | |
| const selector = fullHash.slice(0, 10); // First 4 bytes (8 hex chars + '0x') | |
| console.log('Function signature:', functionSignature); | |
| console.log('Full Keccak256 hash:', fullHash); | |
| console.log('Function selector (first 4 bytes):', selector); | |
| console.log('—'.repeat(40)); | |
| return selector; | |
| } | |
| // 1) Alchemy single execute | |
| console.log('Alchemy single execute selector:'); | |
| calculateFunctionSelector( | |
| 'execute(address,uint256,bytes)' | |
| ); | |
| // 2) Alchemy batch execute | |
| console.log('Alchemy batch execute selector:'); | |
| calculateFunctionSelector( | |
| 'executeBatch((address,uint256,bytes)[])' | |
| ); | |
| // 3) Alchemy execute with runtime validation | |
| console.log('Alchemy execute with runtime validation selector:'); | |
| calculateFunctionSelector( | |
| 'executeWithRuntimeValidation(bytes,bytes)' | |
| ); | |
| // 4) Alchemy entry-point userOp execute | |
| console.log('Alchemy entry-point userOp execute selector:'); | |
| calculateFunctionSelector( | |
| 'executeUserOp((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,address,bytes),bytes32)' | |
| ); | |
| // 5) ZeroDev kernel execute (ERC-7579) | |
| console.log('ZeroDev kernel execute selector:'); | |
| calculateFunctionSelector( | |
| 'execute(bytes32,bytes)' | |
| ); | |
| // 6) Biconomy single execute | |
| console.log('Biconomy single execute selector:'); | |
| calculateFunctionSelector( | |
| 'execute(address,uint256,bytes)' | |
| ); | |
| // 7) Biconomy batch execute | |
| console.log('Biconomy batch execute selector:'); | |
| calculateFunctionSelector( | |
| 'executeBatch(address[],uint256[],bytes[])' | |
| ); | |
| // 8) Biconomy optimized single execute (gas-efficient) | |
| console.log('Biconomy optimized single execute selector:'); | |
| calculateFunctionSelector( | |
| 'execute_ncC(address,uint256,bytes)' | |
| ); | |
| // 9) Biconomy optimized batch execute (gas-efficient) | |
| console.log('Biconomy optimized batch execute selector:'); | |
| calculateFunctionSelector( | |
| 'executeBatch_y6U(address[],uint256[],bytes[])' | |
| ); | |
| // 10) SmartVault (splits) single execute | |
| console.log('SmartVault (splits) single execute selector:'); | |
| calculateFunctionSelector( | |
| 'execute((address,uint256,bytes))' | |
| ); | |
| // 11) SmartVault (splits) batch execute | |
| console.log('SmartVault (splits) batch execute selector:'); | |
| calculateFunctionSelector( | |
| 'executeBatch((address,uint256,bytes)[])' | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment