Git Source
The VmSafe
interface does not allow manipulation of the EVM state or other actions that may
result in Script simulations differing from on-chain execution. It is recommended to only use
these cheats in scripts.
Functions
createWallet
Derives a private key from the name, labels the account with that name, and returns the wallet.
function createWallet(string calldata walletLabel) external returns (Wallet memory wallet);
createWallet
Generates a wallet from the private key and returns the wallet.
function createWallet(uint256 privateKey) external returns (Wallet memory wallet);
createWallet
Generates a wallet from the private key, labels the account with that name, and returns the wallet.
function createWallet(uint256 privateKey, string calldata walletLabel) external returns (Wallet memory wallet);
deriveKey
Derive a private key from a provided mnenomic string (or mnenomic file path)
at the derivation path m/44'/60'/0'/0/{index}
.
function deriveKey(string calldata mnemonic, uint32 index) external pure returns (uint256 privateKey);
deriveKey
Derive a private key from a provided mnenomic string (or mnenomic file path)
at {derivationPath}{index}
.
function deriveKey(string calldata mnemonic, string calldata derivationPath, uint32 index)
external
pure
returns (uint256 privateKey);
deriveKey
Derive a private key from a provided mnenomic string (or mnenomic file path) in the specified language
at the derivation path m/44'/60'/0'/0/{index}
.
function deriveKey(string calldata mnemonic, uint32 index, string calldata language)
external
pure
returns (uint256 privateKey);
deriveKey
Derive a private key from a provided mnenomic string (or mnenomic file path) in the specified language
at {derivationPath}{index}
.
function deriveKey(string calldata mnemonic, string calldata derivationPath, uint32 index, string calldata language)
external
pure
returns (uint256 privateKey);
publicKeyP256
Derives secp256r1 public key from the provided privateKey
.
function publicKeyP256(uint256 privateKey) external pure returns (uint256 publicKeyX, uint256 publicKeyY);
rememberKey
Adds a private key to the local forge wallet and returns the address.
function rememberKey(uint256 privateKey) external returns (address keyAddr);
signCompact
Signs data with a Wallet
.
Returns a compact signature (r
, vs
) as per EIP-2098, where vs
encodes both the
signature's s
value, and the recovery id v
in a single bytes32.
This format reduces the signature size from 65 to 64 bytes.
function signCompact(Wallet calldata wallet, bytes32 digest) external returns (bytes32 r, bytes32 vs);
signCompact
Signs digest
with privateKey
using the secp256k1 curve.
Returns a compact signature (r
, vs
) as per EIP-2098, where vs
encodes both the
signature's s
value, and the recovery id v
in a single bytes32.
This format reduces the signature size from 65 to 64 bytes.
function signCompact(uint256 privateKey, bytes32 digest) external pure returns (bytes32 r, bytes32 vs);
signCompact
Signs digest
with signer provided to script using the secp256k1 curve.
Returns a compact signature (r
, vs
) as per EIP-2098, where vs
encodes both the
signature's s
value, and the recovery id v
in a single bytes32.
This format reduces the signature size from 65 to 64 bytes.
If --sender
is provided, the signer with provided address is used, otherwise,
if exactly one signer is provided to the script, that signer is used.
Raises error if signer passed through --sender
does not match any unlocked signers or
if --sender
is not provided and not exactly one signer is passed to the script.
function signCompact(bytes32 digest) external pure returns (bytes32 r, bytes32 vs);
signCompact
Signs digest
with signer provided to script using the secp256k1 curve.
Returns a compact signature (r
, vs
) as per EIP-2098, where vs
encodes both the
signature's s
value, and the recovery id v
in a single bytes32.
This format reduces the signature size from 65 to 64 bytes.
Raises error if none of the signers passed into the script have provided address.
function signCompact(address signer, bytes32 digest) external pure returns (bytes32 r, bytes32 vs);
signP256
Signs digest
with privateKey
using the secp256r1 curve.
function signP256(uint256 privateKey, bytes32 digest) external pure returns (bytes32 r, bytes32 s);
sign
Signs data with a Wallet
.
function sign(Wallet calldata wallet, bytes32 digest) external returns (uint8 v, bytes32 r, bytes32 s);
sign
Signs digest
with privateKey
using the secp256k1 curve.
function sign(uint256 privateKey, bytes32 digest) external pure returns (uint8 v, bytes32 r, bytes32 s);
sign
Signs digest
with signer provided to script using the secp256k1 curve.
If --sender
is provided, the signer with provided address is used, otherwise,
if exactly one signer is provided to the script, that signer is used.
Raises error if signer passed through --sender
does not match any unlocked signers or
if --sender
is not provided and not exactly one signer is passed to the script.
function sign(bytes32 digest) external pure returns (uint8 v, bytes32 r, bytes32 s);
sign
Signs digest
with signer provided to script using the secp256k1 curve.
Raises error if none of the signers passed into the script have provided address.
function sign(address signer, bytes32 digest) external pure returns (uint8 v, bytes32 r, bytes32 s);
envAddress
Gets the environment variable name
and parses it as address
.
Reverts if the variable was not found or could not be parsed.
function envAddress(string calldata name) external view returns (address value);
envAddress
Gets the environment variable name
and parses it as an array of address
, delimited by delim
.
Reverts if the variable was not found or could not be parsed.
function envAddress(string calldata name, string calldata delim) external view returns (address[] memory value);
envBool
Gets the environment variable name
and parses it as bool
.
Reverts if the variable was not found or could not be parsed.
function envBool(string calldata name) external view returns (bool value);
envBool
Gets the environment variable name
and parses it as an array of bool
, delimited by delim
.
Reverts if the variable was not found or could not be parsed.
function envBool(string calldata name, string calldata delim) external view returns (bool[] memory value);
envBytes32
Gets the environment variable name
and parses it as bytes32
.
Reverts if the variable was not found or could not be parsed.
function envBytes32(string calldata name) external view returns (bytes32 value);
envBytes32
Gets the environment variable name
and parses it as an array of bytes32
, delimited by delim
.
Reverts if the variable was not found or could not be parsed.
function envBytes32(string calldata name, string calldata delim) external view returns (bytes32[] memory value);
envBytes
Gets the environment variable name
and parses it as bytes
.
Reverts if the variable was not found or could not be parsed.
function envBytes(string calldata name) external view returns (bytes memory value);
envBytes
Gets the environment variable name
and parses it as an array of bytes
, delimited by delim
.
Reverts if the variable was not found or could not be parsed.
function envBytes(string calldata name, string calldata delim) external view returns (bytes[] memory value);
envExists
Gets the environment variable name
and returns true if it exists, else returns false.
function envExists(string calldata name) external view returns (bool result);
envInt
Gets the environment variable name
and parses it as int256
.
Reverts if the variable was not found or could not be parsed.
function envInt(string calldata name) external view returns (int256 value);
envInt
Gets the environment variable name
and parses it as an array of int256
, delimited by delim
.
Reverts if the variable was not found or could not be parsed.
function envInt(string calldata name, string calldata delim) external view returns (int256[] memory value);
envOr
Gets the environment variable name
and parses it as bool
.
Reverts if the variable could not be parsed.
Returns defaultValue
if the variable was not found.
function envOr(string calldata name, bool defaultValue) external view returns (bool value);
envOr
Gets the environment variable name
and parses it as uint256
.
Reverts if the variable could not be parsed.
Returns defaultValue
if the variable was not found.
function envOr(string calldata name, uint256 defaultValue) external view returns (uint256 value);
envOr
Gets the environment variable name
and parses it as an array of address
, delimited by delim
.
Reverts if the variable could not be parsed.
Returns defaultValue
if the variable was not found.
function envOr(string calldata name, string calldata delim, address[] calldata defaultValue)
external
view
returns (address[] memory value);
envOr
Gets the environment variable name
and parses it as an array of bytes32
, delimited by delim
.
Reverts if the variable could not be parsed.
Returns defaultValue
if the variable was not found.
function envOr(string calldata name, string calldata delim, bytes32[] calldata defaultValue)
external
view
returns (bytes32[] memory value);
envOr
Gets the environment variable name
and parses it as an array of string
, delimited by delim
.
Reverts if the variable could not be parsed.
Returns defaultValue
if the variable was not found.
function envOr(string calldata name, string calldata delim, string[] calldata defaultValue)
external
view
returns (string[] memory value);
envOr
Gets the environment variable name
and parses it as an array of bytes
, delimited by delim
.
Reverts if the variable could not be parsed.
Returns defaultValue
if the variable was not found.
function envOr(string calldata name, string calldata delim, bytes[] calldata defaultValue)
external
view
returns (bytes[] memory value);
envOr
Gets the environment variable name
and parses it as int256
.
Reverts if the variable could not be parsed.
Returns defaultValue
if the variable was not found.
function envOr(string calldata name, int256 defaultValue) external view returns (int256 value);
envOr