# prompt

Description: prompt cheatcode documentation

Note: This document was authored using MDX

  Source: https://github.com/NomicFoundation/hardhat-website/tree/main/src/content/docs/docs/reference/cheatcodes/External/prompt.mdx

  Components used in this page:
    - :::note: An informational callout block. Supports custom title `:::note[Title]` and icon `:::note{icon="name"}` syntax.

{/* This document contains content copied/adapted from the Foundry Book (MIT licensed). See LICENSE in the parent directory. */}

### Signature

```solidity
function prompt(
  string calldata promptText
) external returns (string memory input);
function promptSecret(
  string calldata promptText
) external returns (string memory input);
function promptSecretUint(
  string calldata promptText
) external returns (uint256);
```

### Description

Display an interactive prompt to the user for inserting arbitrary data.

`vm.prompt` displays an interactive input, while `vm.promptSecret` & `vm.promptSecretUint` display a
hidden input, used for passwords and other secret information that should not
leak to the terminal.

:::note
This cheatcode is meant to be used in scripts ― not tests. It is also advised to
follow the best practices below for testing scripts that use `vm.prompt` and
handling timeouts, since scripts might otherwise hang or revert. This cheatcode
reverts when running in a non-interactive shell.
:::

### Configuration

In order to prevent unwanted hangups, `vm.prompt` has a timeout configuration.

In your [Solidity tests configuration](https://hardhat.org/docs/reference/configuration#solidity-tests-configuration), you can set it using `promptTimeout = 120`.

Default value is `120` and values are in seconds.

### Best practices

#### Testing scripts that use `vm.prompt`

When testing scripts containing `vm.prompt` it is recommended to use the
following pattern:

```solidity
contract Script {
  function run() public {
    uint256 myUint = vm.parseUint(vm.prompt("enter uint"));
    run(myUint);
  }

  function run(uint256 myUint) public {
    // actual logic
  }
}
```

That way, we are keeping the UX gain (don't have to provide `--sig` argument
when running the script), but tests can set any value to `myUint` and not just
a hardcoded default.

#### Handling timeouts

When a user fails to provide an input before the timeout expires, the
`vm.prompt` cheatcode reverts. If you'd like, timeouts can be handled by using
`try/catch`:

```solidity
string memory input;

try vm.prompt("Username") returns (string memory res) {
    input = res;
}
catch (bytes memory) {
    input = "Anonymous";
}
```

### Examples

#### Choose RPC endpoint

Provide an option to choose the RPC/chain to run on.

In your [Solidity tests configuration](https://hardhat.org/docs/reference/configuration#solidity-tests-configuration):

```js
forking: {
    rpcEndpoints: {
        mainnet: "https://eth.llamarpc.com",
        polygon: "https://polygon.llamarpc.com",
    }
}
```

In your script:

```solidity
string memory rpcEndpoint = vm.prompt("RPC endpoint");
vm.createSelectFork(rpcEndpoint);
```
