Created
May 18, 2022 01:33
-
-
Save 0xJohnnyGault/ce510f71c3d0815570f610832d1db574 to your computer and use it in GitHub Desktop.
Create a keccak256/abi.encodePacked hash
This file contains 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
#!/usr/bin/env bash | |
set -Eeuo pipefail | |
trap 'rm -f -- "${TMPFILE}"' EXIT | |
TMPFILE=$(mktemp) || exit 1 | |
cat << EOF > ${TMPFILE} | |
pragma solidity ^0.8.0; | |
contract Hasher { | |
function run() external pure returns (bytes32) { | |
return keccak256(abi.encodePacked("${1:-}","${2:-}","${3:-}","${4:-}","${5:-}","${6:-}")); | |
} | |
} | |
EOF | |
re='bytes32 (0x[0-9a-f]+)' | |
[[ `forge run ${TMPFILE}` =~ ${re} ]] | |
hash=${BASH_REMATCH[1]} | |
echo ${hash} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment