> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenderly.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Virtual Environments via API

> Script the creation of single-network and Multichain Virtual Environments using the Tenderly REST API. Useful for CI/CD and per-PR environments.

Use the REST API to create Virtual Environments from scripts, CI/CD jobs, or any backend. The same endpoints back the dashboard.

For the full request and response schemas, see the [REST API reference](/virtual-environments/rest-api).

## Before you begin

* A [Tenderly access key](/platform/account/projects/api-tokens). Export it as `TENDERLY_ACCESS_KEY` in your shell.
* Your account and project slugs, available in the URL of your Tenderly Dashboard.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export TENDERLY_ACCESS_KEY=# the key you copied
```

## Create a single-network Virtual Environment

<Steps>
  ### Call the API

  `POST` to the `vnets` endpoint with your fork and chain configuration:

  ```bash title="testnet-create.sh" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  RESPONSE=$(curl --request POST \
    --url https://api.tenderly.co/api/v1/account/me/project/project/vnets \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --header "X-Access-Key: ${TENDERLY_ACCESS_KEY}" \
    --data '{
      "slug": "my-staging-testnet-25",
      "display_name": "My Staging TestNet",
      "fork_config":            { "network_id": 1, "block_number": "latest" },
      "virtual_network_config": { "chain_config": { "chain_id": 73571 } },
      "sync_state_config":      { "enabled": false, "commitment_level": "latest" },
      "explorer_page_config":   { "enabled": false, "verification_visibility": "bytecode" }
    }')
  ```

  ### Extract the Admin RPC URL

  The `rpcs` array on the response contains the Admin and Public RPC URLs. Pull the Admin RPC out for the rest of your script:

  ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  ADMIN_RPC=$(echo $RESPONSE | jq -r '.rpcs[] | select(.name == "Admin RPC") | .url')
  ```
</Steps>

## Create a Multichain Virtual Environment

A [Multichain Virtual Environment](/virtual-environments/multichain/overview) is created in a single call via the `multivnets` endpoint. All networks in the call are grouped under one `stack_id`, which is what makes cross-chain bridging possible between them.

```bash title="multivnet-create.sh" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
curl --location 'https://api.tenderly.co/api/v1/account/me/project/project/multivnets' \
  --header 'accept: application/json, text/plain, */*' \
  --header "X-Access-Key: ${TENDERLY_ACCESS_KEY}" \
  --header 'content-type: application/json' \
  --data '{
    "vnets": [
      {
        "slug": "mainnet-staging",
        "fork_config":            { "network_id": 1,     "block_number": "latest" },
        "virtual_network_config": { "chain_config": { "chain_id": 1 } }
      },
      {
        "slug": "arbitrum-staging",
        "fork_config":            { "network_id": 42161, "block_number": "latest" },
        "virtual_network_config": { "chain_config": { "chain_id": 42161 } }
      },
      {
        "slug": "base-staging",
        "fork_config":            { "network_id": 8453,  "block_number": "latest" },
        "virtual_network_config": { "chain_config": { "chain_id": 8453 } }
      }
    ]
  }'
```

Each entry in the `vnets` array creates one network inside the Multichain Virtual Environment. The response returns a `stack_id` and an array of Virtual Environment objects, each with its own RPC endpoints.

See the [REST API reference](/virtual-environments/rest-api#create-a-multichain-virtual-environment) for the field-by-field schema.

## Next steps

* [Set up GitHub Actions with Foundry](/virtual-environments/ci-cd/github-actions-foundry) or [Hardhat](/virtual-environments/ci-cd/github-actions-hardhat) to provision Virtual Environments per pull request.
* [Stage contracts](/virtual-environments/ci-cd/stage-contracts) on the Virtual Environment you just created.
* Browse the full [REST API reference](/virtual-environments/rest-api).
