> For the complete documentation index, see [llms.txt](https://docs.blocktorch.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blocktorch.xyz/concepts/data-sources/local-forks/hardhat-forking-api.md).

# Hardhat forking API

## Authentication

All API requests require the use of an API key. You must include your API key in the header of each request. Your API key authenticates your account with the service.

```
x-api-key: {{API_KEY}}
```

Replace `{{API_KEY}}` with your actual API key provided upon account registration.

### Creating a new API key

1. Navigate to the `Settings` page in your project
2. Scroll down to API Setting and create a new API key

<figure><img src="/files/OzHuRdV9DMNGD5PHwErk" alt="" width="563"><figcaption></figcaption></figure>

3. Give your API key a name and store the secret. Ensure to keep your API key confidential for your Account's security.

<figure><img src="/files/3egWV1afQufmyWYtWqBe" alt="" width="540"><figcaption></figcaption></figure>

### API Base URL

```
https://c6yaznpyf4.execute-api.us-east-1.amazonaws.com/prod/api
```

All endpoints referenced in this documentation start with the above base URL

## Endpoints

### Creating Hardhat Instance

<mark style="color:green;">`POST`</mark> `/hardhat/`{{PROJECT\_ID}}

Creates a new Hardhat instance for a given project.

**Headers**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |
| x-api-key    | {{API\_KEY}}       |

**Data Parameters**

| Name        | Type   | Description                                                           |
| ----------- | ------ | --------------------------------------------------------------------- |
| providerUrl | string | The URL of the Ethereum provider the Hardhat instance will connect to |

**Sample call**

* Replace `{{PROJECT_ID}}` with the appropriate project ID
* Replace `{{PROVIDER_URL}}` with the URL of your Ethereum provider
* Ensure that the `API_KEY` is kept secure and not exposed in shared or public environments

```
curl --location 'https://c6yaznpyf4.execute-api.us-east-1.amazonaws.com/prod/api/hardhat/{{PROJECT_ID}}' \
--header 'x-api-key: {{API_KEY}}' \
--header 'Content-Type: application/json' \
--data '{
    "providerUrl": "{{PROVIDER_URL}}"
}'
```

**Sample Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "message": "Hardhat instance created successfully", 
  "instanceId": 420
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}

### Deleting Hardhat instance

<mark style="color:red;">`DELETE`</mark> `/hardhat/{{PROJECT_ID}}/{{CHAIN_ID}}`

Deletes an existing Hardhat instance from a specific project and chain.

**Headers**

| Name      | Value        |
| --------- | ------------ |
| x-api-key | {{API\_KEY}} |

**Sample Call**

* Replace `{{PROJECT_ID}}` and `{{CHAIN_ID}}` with the appropriate project and chain IDs
* Ensure that the `API_KEY` is kept secure and not exposed in shared or public environments.

```
curl --location --request DELETE 'https://c6yaznpyf4.execute-api.us-east-1.amazonaws.com/prod/api/hardhat/{{PROJECT_ID}}/{{CHAIN_ID}}' \
--header 'x-api-key: {{API_KEY}}'
```

**Sample Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "message": "Hardhat instance deleted successfully"
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.blocktorch.xyz/concepts/data-sources/local-forks/hardhat-forking-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
