getHashData
Calculate Solidity function selectors, event hashes, decode calldata, and sign messages.
Features
- Hash Calculation: Compute Keccak-256 hashes for Solidity function signatures and event signatures
- Function Selectors: Get 4-byte function selectors for contract calls
- Selector Lookup: Reverse lookup function signatures using 4byte.directory API
- Calldata Decoding: Decode calldata with ABI or auto-detect via 4byte.directory
- Message Signing: Sign messages and hashes with Ethereum private keys
- Address Checksum: Convert Ethereum addresses to checksummed format
Installation
pip install getHashData
Quick Start
Calculate Function Selector
getHash -f -s "transfer(address,uint256)"
# Output: 0xa9059cbb transfer(address,uint256)
Calculate Event Hash
getHash -s "Transfer(address,address,uint256)"
# Output: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef Transfer(address,address,uint256)
Lookup Function Signature
getHash --lookup 0xa9059cbb
# Output: Selector 0xa9059cbb:
# transfer(address,uint256)
# transfer(address,uint)
Decode Calldata (Auto-detect)
getHash --decode-auto 0xa9059cbb0000000000000000000000005aaeb6053ba3eedb6a475a1c689177b8d1c56f4d0000000000000000000000000000000000000000000000000de0b6b3a7640000
# Output: Signature: transfer(address,uint256)
# Function: transfer
# Parameters:
# [address] param0: 0x5aAeb6053ba3EEdb6a475A1c689177B8d1c56f4d
# [uint256] param1: 1000000000000000000
Sign Message
getHash --sign -k <private_key> -d "Hello, Ethereum!"
# Output: messageHash: 0x...
# r: ...
# s: ...
# v: ...
# signature: 0x...
Address Checksum
getHash --checksum 0x5aaeb6053ba3eedb6a475a1c689177b8d1c56f4d
# Output: 0x5aAeb6053ba3EEdb6a475A1c689177B8d1c56f4d
CLI Usage
usage: getHash [-h] [-s STRING] [-i INPUT_FILE] [-a ABI_FILE] [-o OUTPUT_FILE]
[-w] [-f] [-k PRIVATE_KEY] [-d DATA] [--hex HEX_DATA]
[--sign] [--lookup LOOKUP_SELECTOR] [--decode DECODE_CALLDATA]
[--decode-auto DECODE_CALLDATA_AUTO] [--checksum CHECKSUM_ADDR]
[--json]
Calculate Solidity function selectors, event hashes, and sign messages.
optional arguments:
-h, --help show this help message and exit
-s STRING, --string STRING
Function or event signature string.
-i INPUT_FILE, --input INPUT_FILE
Input Solidity file path.
-a ABI_FILE, --abi ABI_FILE
Input ABI JSON file path.
-o OUTPUT_FILE, --output OUTPUT_FILE
Output file path.
-w, --web3 Use Web3 library.
-f, --function Parse as function (default: event).
-k PRIVATE_KEY, --key PRIVATE_KEY
Private key for signing.
-d DATA, --data DATA Message to sign.
--hex HEX_DATA Hash to sign (hex format).
--sign Sign a message or hash.
--lookup LOOKUP_SELECTOR
Lookup function signature by selector.
--decode DECODE_CALLDATA
Decode calldata (requires ABI file).
--decode-auto DECODE_CALLDATA_AUTO
Decode calldata automatically (no ABI needed).
--checksum CHECKSUM_ADDR
Convert address to checksum format.
--json Output as JSON.
Python API
Hash Calculation
from getHashData import HashCalculator
calc = HashCalculator(use_web3=False)
selector = calc.calculate_hash("transfer(address,uint256)", is_function=True)
print(selector) # 0xa9059cbb
event_hash = calc.calculate_hash("Transfer(address,address,uint256)", is_function=False)
print(event_hash) # 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
Signature Parsing
from getHashData import SignatureParser
# Parse signature
sig = SignatureParser.parse_signature("transfer(address,uint256)")
print(sig) # transfer(address,uint256)
# Extract from ABI file
sigs = SignatureParser.extract_from_abi("abi.json", is_function=True)
print(sigs) # ['transfer(address,uint256)', 'approve(address,uint256)', ...]
Selector Lookup
from getHashData import SelectorLookup
# Lookup signatures for a selector
sigs = SelectorLookup.lookup_selector("0xa9059cbb")
print(sigs) # ['transfer(address,uint256)', 'transfer(address,uint)', ...]
Calldata Decoding
from getHashData import CalldataDecoder
# Auto-decode (no ABI needed)
result = CalldataDecoder.decode_calldata_auto(
"0xa9059cbb0000000000000000000000005aaeb6053ba3eedb6a475a1c689177b8d1c56f4d0000000000000000000000000000000000000000000000000de0b6b3a7640000"
)
print(result)
# {
# 'selector': '0xa9059cbb',
# 'signature': 'transfer(address,uint256)',
# 'function': 'transfer',
# 'param_types': ['address', 'uint256'],
# 'params': {
# 'param0': '0x5aAeb6053ba3EEdb6a475A1c689177B8d1c56f4d',
# 'param1': 1000000000000000000
# }
# }
Message Signing
from getHashData import MessageSigner
signer = MessageSigner()
result = signer.sign_message("Hello, Ethereum!", private_key)
print(result)
# {
# 'messageHash': '0x...',
# 'r': ...,
# 's': ...,
# 'v': ...,
# 'signature': '0x...'
# }
Address Checksum
from getHashData import AddressChecksum
# Checksum address
addr = AddressChecksum.checksum("0x5aaeb6053ba3eedb6a475a1c689177b8d1c56f4d")
print(addr) # 0x5aAeb6053ba3EEdb6a475A1c689177B8d1c56f4d
# Validate address
is_valid = AddressChecksum.is_valid("0x5aAeb6053ba3EEdb6a475A1c689177B8d1c56f4d")
print(is_valid) # True
Project Structure
getHashData/
├── __init__.py # Package exports
├── cli.py # CLI entry point
└── modules/
├── hasher.py # Keccak-256 hash calculation
├── parser.py # Solidity signature parsing
├── lookup.py # 4byte.directory API integration
├── decoder.py # Calldata decoding
└── crypto.py # Address checksum & message signing
tests/
├── test_parser.py # Parser tests
├── test_hasher.py # Hash calculator tests
├── test_crypto.py # Crypto utilities tests
├── test_lookup.py # Selector lookup tests
└── test_decoder.py # Calldata decoder tests
Dependencies
web3- Ethereum Web3 librarypysha3- Keccak-256 hashingrequests- HTTP client for API callseth-abi- Ethereum ABI encoding/decoding
Testing
Run the test suite:
pytest tests/ -v
All 61 tests pass with full coverage of core functionality.
License
MIT
Author
th35tr0n9
Metadata
Release files for getHashData 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| gethashdata-0.5.0.tar.gz | 17.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gethashdata-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.1 kB
Release files / gethashdata-0.5.0.tar.gz
| Download URL | gethashdata-0.5.0.tar.gz |
|---|---|
| Size | 17.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4cf0721afebe37cb272b2c1c6fd7b14e0c9e479186a84c0ab46b89eb4ead2612
|
|
BLAKE2b-256 checksum How to use checksums |
b4feb96f419ff9282c66eed73a4f26d8dfb89b92bf43316e346f4d09ee4a3fdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / gethashdata-0.5.0-py3-none-any.whl
| Download URL | gethashdata-0.5.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3e41e97101c40e25b50ad230edb970142e7d2942de4529095bd244c7a992298
|
|
BLAKE2b-256 checksum How to use checksums |
29620c9a38e912f42a6f2c2ed5da983293a98fe15de25083eb2dc467b3b0a78b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Security for getHashData 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.