Skip to content

Instantly share code, notes, and snippets.

@jaybuidl
Last active June 19, 2023 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaybuidl/bcc5edf2e811f5386bf96e240a0a073b to your computer and use it in GitHub Desktop.
Save jaybuidl/bcc5edf2e811f5386bf96e240a0a073b to your computer and use it in GitHub Desktop.
Once Foundry is installed, the script uses cast to generate a burner wallet stored in an unencrypted keystore file under ./test-keystore/, then it signs and verifies a "hello world!" message.
#!/usr/bin/env bash
# cast is required: https://book.getfoundry.sh/getting-started/installation
[ ! -x "$(command -v cast)" ] && echo "cast is not installed, please run 'curl -L https://foundry.paradigm.xyz | bash'." && exit 1
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ETH_KEYSTORE_DIR=$SCRIPT_DIR/test-keystore
if [ ! -d "$ETH_KEYSTORE_DIR" ]; then
echo "Creating test keystore"
mkdir $ETH_KEYSTORE_DIR
export ETH_KEYSTORE=$(cast wallet new "$ETH_KEYSTORE_DIR" --unsafe-password "" | head -1 | sed 's/^.*: //')
else
echo "Using existing keystore"
export ETH_KEYSTORE="$ETH_KEYSTORE_DIR/$(ls -1 $ETH_KEYSTORE_DIR | head -1)"
fi
ethAddress=$(cast wallet address --password "")
echo "Using address $ethAddress"
message="hello world!"
# Sign
signature=$(cast wallet sign --password "" "$message")
# Verify
cast wallet verify --address $ethAddress "$message" $signature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment