Skip to content

Instantly share code, notes, and snippets.

@0xJohnnyGault
Created May 18, 2022 01:33
Show Gist options
  • Save 0xJohnnyGault/ce510f71c3d0815570f610832d1db574 to your computer and use it in GitHub Desktop.
Save 0xJohnnyGault/ce510f71c3d0815570f610832d1db574 to your computer and use it in GitHub Desktop.
Create a keccak256/abi.encodePacked hash
#!/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