Skip to content

Instantly share code, notes, and snippets.

@pikonha
Created June 18, 2025 21:39
Show Gist options
  • Select an option

  • Save pikonha/d03ab9f83bc1dab30112416c4f1351f0 to your computer and use it in GitHub Desktop.

Select an option

Save pikonha/d03ab9f83bc1dab30112416c4f1351f0 to your computer and use it in GitHub Desktop.

Keystores provide a better way to handle private keys by storing them on encrypted files instead of on a regular .env or even exported on the terminal.

Default keystore directory: ~/foundry/keystore

Create a new keystore

# Creates a new private key and outputs to the terminal
cast wallet new 

# Creates a new private key and saves on a file
cast wallet new ./pvt_key

Imports a private key

It will ask for a password that will be required to use the keystore on any action.

# Stores a private key on a encrypted keystore named `blockful`
 cast wallet import blockful --private-key 0x....
⚠️

Remember to add a blank space at the beggining of the command so it doesn't get stored on the terminal history

Running a script with a keystore

# Runs a script using the given private key as signer
cast wallet script script/deploy/Contract.sol --account blockful

Dealing with signatures

# Signs a message using the given private key
cast wallet sign <MESSAGE> --account blockful

# Verifies a signature
cast wallet verify <MESSAGE> <SIGNATURE> --account blockful
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment