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

# Using Foundry

> Deploy and test smart contracts on MANTRA Chain using Foundry

Foundry is a fast, Solidity-native development toolkit for Ethereum smart contracts. It's known for its blazing-fast speed and Solidity-centric approach, making it a great alternative to JavaScript-based tools like Hardhat.

> [!NOTE]
>
> **Foundry Tutorial Resources:**
>
> * [Foundry Book - Creating a New Project](https://book.getfoundry.sh/projects/creating-a-new-project)
> * [QuickNode - Intro to Foundry](https://www.quicknode.com/guides/ethereum-development/smart-contracts/intro-to-foundry)

## Installation

Foundry installation is straightforward. Install using the official installer:

```bash theme={null}
curl -L https://foundry.paradigm.xyz | bash
```

After running the installer, follow the instructions to re-open your terminal (or use `source` to reload environment variables), then run:

```bash theme={null}
foundryup
```

Running `foundryup` will automatically install the latest stable version of the precompiled binaries:

* `forge` - Build, test, and deploy tool
* `cast` - CLI for interacting with contracts
* `anvil` - Local testnet node
* `chisel` - Solidity REPL

## Creating a New Project

Initialize a new Foundry project:

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

This creates a standard Foundry project structure with:

* `src/` - Your Solidity contracts
* `test/` - Your test files
* `script/` - Deployment scripts
* `foundry.toml` - Configuration file

## Configuring for MANTRA Chain

Update `foundry.toml` to configure MANTRA Chain networks:

```toml theme={null}
[rpc_endpoints]
mantra_mainnet = "https://evm.mantrachain.io"
mantra_testnet = "https://evm.dukong.mantrachain.io"

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.23"

[profile.mantra_mainnet]
chain_id = 5888
rpc_url = "https://evm.mantrachain.io"

[profile.mantra_testnet]
chain_id = 5887
rpc_url = "https://evm.dukong.mantrachain.io"
```

## Building Contracts

Build your contracts:

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

## Testing

Write tests in Solidity and run them:

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

## Deploying

Deploy to MANTRA Chain testnet:

```bash theme={null}
forge create MyContract \
  --rpc-url https://evm.dukong.mantrachain.io \
  --private-key $PRIVATE_KEY \
  --chain-id 5887
```

## Deployment walkthrough (legacy pattern)

If you prefer keeping deployment config in a `.env` file (handy for scripts/CI), you can use a pattern like:

```bash theme={null}
FOUNDRY_PROFILE=mantra_testnet
FOUNDRY_PK=<YOUR_PRIVATE_KEY>
RPC_URL_MANTRA_EVM=https://evm.dukong.mantrachain.io
```

Then:

```bash theme={null}
source .env
forge create --rpc-url "$RPC_URL_MANTRA_EVM" --private-key "$FOUNDRY_PK" src/Counter.sol:Counter
```

## Next Steps

* Learn about [deploying contracts](https://mantrachain.mintlify.site/developers/evm/deploying-contracts.md)
* Understand [contract verification](https://mantrachain.mintlify.site/developers/evm/verifying-contracts.md)
* Explore [EVM development](https://mantrachain.mintlify.site/developers/evm/getting-started.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.