---
description: Displays an interactive prompt for user input in scripts
---

## `prompt`

### 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

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

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

### Parameters

| Parameter    | Type     | Description                     |
| ------------ | -------- | ------------------------------- |
| `promptText` | `string` | The text to display to the user |

### Returns

| Type      | Description                                              |
| --------- | -------------------------------------------------------- |
| `string`  | The user's input (for `prompt` and `promptSecret`)       |
| `uint256` | The user's input parsed as uint (for `promptSecretUint`) |

### Configuration

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

In your `foundry.toml`:

```toml
prompt_timeout = 120
```

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

### Examples

#### Choose RPC endpoint

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

In your `foundry.toml` file:

```toml [foundry.toml]
[rpc_endpoints]
mainnet = "https://eth.llamarpc.com"
polygon = "https://polygon.llamarpc.com"
```

In your script:

```solidity [script/Deploy.s.sol]
string memory rpcEndpoint = vm.prompt("RPC endpoint");
vm.createSelectFork(rpcEndpoint);
```

#### Parse user input into native types

Use string parsing cheatcodes to parse user responses:

```solidity [script/Transfer.s.sol]
uint privateKey = vm.promptSecretUint("Private key");
address to = vm.parseAddress(vm.prompt("Send to"));
uint amount = vm.parseUint(vm.prompt("Amount (wei)"));
vm.broadcast(privateKey);
payable(to).transfer(amount);
```

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

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

```solidity [script/MyScript.s.sol]
contract Script {
    function run() public {
        uint256 myUint = vm.parseUint(vm.prompt("enter uint"));
        run(myUint);
    }

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

This keeps 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. Timeouts can be handled using `try/catch`:

```solidity [script/PromptWithDefault.s.sol]
string memory input;

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

### Gotchas

:::warning
This cheatcode is meant to be used in scripts, not tests. It also reverts when running in a non-interactive shell.
:::

:::note
Follow the best practices above for testing scripts that use `vm.prompt` and handling timeouts, since scripts might otherwise hang or revert.
:::

:::note
When a `forge script` deploys a contract that requires **external library linking**, `vm.prompt` will display the same prompt **twice**. This happens because Foundry runs the script twice internally — once for simulation and once for broadcast — and each run triggers the prompt independently. To work around this, consider passing values as script arguments or reading from environment variables with [`vm.envString`](/reference/cheatcodes/env-string) instead of using `vm.prompt` in scripts that link against external libraries.
:::

### Related Cheatcodes

- [`parseUint`](/reference/cheatcodes/parse-uint) - Parse string to uint
- [`parseAddress`](/reference/cheatcodes/parse-address) - Parse string to address
- [`envString`](/reference/cheatcodes/env-string) - Read environment variables as an alternative to interactive prompts
