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

# Setup Foundry

> Guide to setting up Foundry for SKALE development

## Setup Foundry

Foundry is a blazing fast, portable, and modular toolkit for Ethereum application development written in Rust. This guide will help you set up Foundry for developing on SKALE.

## Prerequisites

* [Rust](https://www.rust-lang.org/tools/install) installed on your machine
* Basic command-line knowledge

<Note>
  If you are on a Windows machine, you will need to use Windows Subsystem for Linux (WSL), since Foundry doesn't work natively on Windows.
</Note>

## Step 1: Install Foundry

Install Foundry by running:

```shell theme={null}
foundryup
```

This will install the latest stable release of Foundry, including:

* **Forge**: Build, test, and deploy smart contracts
* **Cast**: Interact with EVM smart contracts, send transactions, and read chain data
* **Anvil**: Local Ethereum node for testing
* **Chisel**: Solidity REPL

## Step 2: Verify Installation

Verify that Foundry is installed correctly:

```shell theme={null}
forge --version
cast --version
anvil --version
```

You should see version numbers for each tool.

## Step 3: Create a New Foundry Project

Create a new Foundry project:

```shell theme={null}
forge init my-skale-project
cd my-skale-project
```

This creates a new directory with the following structure:

```
my-skale-project/
├── src/          # Smart contracts
├── script/       # Deployment scripts
├── test/         # Test files
├── lib/          # Dependencies
├── foundry.toml  # Configuration file
└── remappings.txt # Import remappings
```

## Step 4: Configure Foundry for SKALE

Update the `foundry.toml` file to add SKALE Chain endpoints:

```toml theme={null}
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

# SKALE Chain Configuration
[rpc_endpoints]
skale_testnet = "https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha"
skale_mainnet = "https://skale-base.skalenodes.com/v1/base"
# Add your custom SKALE Chain endpoint here

[etherscan]
skale_testnet = { key = "", url = "https://base-sepolia-testnet-explorer.skalenodes.com/api" }
skale_mainnet = { key = "", url = "https://skale-base-explorer.skalenodes.com/api" }
```

<Note>
  Replace the RPC URLs with your specific SKALE Chain endpoint. You can find SKALE Chain endpoints in the [SKALE Portal](https://portal.skale.space).
</Note>

## Step 5: Install Dependencies

Install OpenZeppelin Contracts (or other dependencies):

```shell theme={null}
forge install OpenZeppelin/openzeppelin-contracts
```

This will add the dependency to your `lib` directory.

## Step 6: Create a Keystore (Optional but Recommended)

For secure deployment, create a Foundry keystore:

```shell theme={null}
cast wallet import skale-deployer --private-key $(cast wallet new | grep 'Private key:' | awk '{print $3}')
```

<Note>
  Provide a password to encrypt the keystore file. If you forget this password, you will not be able to recover it.
</Note>

Get your wallet address:

```shell theme={null}
cast wallet address --account skale-deployer
```

Copy this address and fund it with sFUEL from the [sFUEL Station](https://sfuelstation).

## Step 7: Test Your Setup

Compile your contracts:

```shell theme={null}
forge build
```

Run tests:

```shell theme={null}
forge test
```

## SKALE-Specific Considerations

When deploying to SKALE, remember to:

1. **Use the `--legacy` flag**: SKALE Chains require legacy transaction format
   ```shell theme={null}
   forge create src/MyContract.sol:MyContract \
       --account skale-deployer \
       --rpc-url skale_testnet \
       --broadcast \
       --legacy
   ```

2. **Use `--slow` flag for scripts**: When running scripts with multiple transactions
   ```shell theme={null}
   forge script script/Deploy.s.sol \
       --account skale-deployer \
       --rpc-url skale_testnet \
       --broadcast \
       --slow \
       --legacy
   ```

3. **Verify contracts**: Use the block explorer API for verification
   ```shell theme={null}
   forge verify-contract \
       --rpc-url skale_testnet \
       <CONTRACT_ADDRESS> \
       src/MyContract.sol:MyContract \
       --verifier blockscout \
       --verifier-url https://base-sepolia-testnet-explorer.skalenodes.com/api
   ```

## Related Topics

* [Setup Hardhat](/cookbook/deployment/setup-hardhat)
* [Deploy on SKALE](/developers/deploy-on-skale)
* [Troubleshooting](/developers/troubleshooting)
