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

# Deploy Smart Contract

In the previous section you learned how to create a simple smart contract to store and retrieve an integer from the blockchain. Now it's time to **deploy** this contract to peaq network.
Deployment is the process of broadcasting your contract's **bytecode** to to the blockchain - making it possible to interact with. This guide will show you how to deploy using **Remix**, **Hardhat**, and **Foundry**,
three popular tools for EVM smart contract development.

## Prerequisites

* Completion of the [Build Smart Contract](/peaqchain/build/basic-operations/smart-contracts/build-smart-contract) guide.
* Access to a [MetaMask wallet](/peaqchain/build/getting-started/get-test-tokens#create-evm-wallet) connected to the peaq/agung network.

## Instructions

### Deploying with Remix

#### 1. Compile the Smart Contract

* **Open the Compile Sidebar in Remix:**
  * Select the **Solidity Compiler** from the left sidebar.
* **Compile the Contract:**
  * Ensure the Solidity version matches the pragma directive in your contract (e.g., `^0.8.0`).
  * Click the **Compile SimpleStorage.sol** button.
  * Ensure green checkmark has appeared after successful compilation.

#### 2. Deploy the Contract

* **Open the Deploy & Run Transactions Sidebar:**
  * Select the **Deploy & Run Transactions** option in the Remix sidebar.
* **Select the Environment:**
  * From the **Environment** dropdown, select **Injected Provider - MetaMask**.
  * Confirm that MetaMask is connected to the appropriate network by checking the **Chain ID**.
* **Deploy the Contract:**
  * Click the orange **Deploy** button to initiate the transaction.
  * A MetaMask popup will appear for transaction confirmation. Ensure you have sufficient `$AGUNG/$PEAQ` tokens in your wallet for gas fees.

#### 3. View Deployment Details

Once the transaction is confirmed, the Remix console will display deployment logs, including:

* **Transaction Hash:** Unique identifier for the transaction sent to the blockchain. The hash allows you to track and and verify the transaction on the chain. It acts like a deployment receipt. You can use this transaction hash in an explorer to view detailed information about the transaction.
* **Block Number:** The number of the block your transaction was included on-chain. Blocks are used to group transactions together and the number is used to indicate where your contract deployment was recorded.
* **Gas Used:** The amount of computational effort that the blockchain required to process your transaction. Deploying a contract consumes gas since it involves writing the bytecode on-chain. Gas is used to show how resource-intensive the deployment was.
* **Contract Address:** The unique address assigned to your deployed smart contract on the blockchain. This address allows you and other users to interact with your contract. It is the location of the contract on the blockchain network.

### Deploying with Hardhat

#### 1. Create a Deployment Script

* **Set Up the Script:**
  * In the `ignition/modules/` folder, create a file named `SimpleStorage.js`
* **Add Deployment Logic:**
  * Add the following code to deploy your `SimpleStorage` js file:
  ```javascript theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
  const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");

  module.exports = buildModule("SimpleStorageModule", (m) => {
    const SimpleStorage = m.contract("SimpleStorage", []);

    return { SimpleStorage };
  });

  ```

#### 2. Deploy the Contract

* **Run the Deployment Command:**
  * In your terminal, navigate to the project's root directory
  * Execute the following command to deploy the contract to the agung test network:
  ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
  npx hardhat ignition deploy ./ignition/modules/SimpleStorage.js --network agung
  ```

* **View Deployment Output:**
  * Upon successful deployment, the terminal will display:
    * **Deployed Contract Address:** The unique address assigned to your deployed smart contract on the blockchain. Record the contract address for future interactions.

### Deploying with Foundry

Use Foundry to deploy using `forge create` or a script.

#### 1. Prepare environment

Create a `.env` in your project root with:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
RPC_URL="https://..."           # peaq or agung RPC URL
PRIVATE_KEY="<hex_with_0x>"  # deployer key
```

#### 2. Option A — `forge create`

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
source .env
forge create src/SimpleStorage.sol:SimpleStorage \
  --rpc-url "$RPC_URL" \
  --private-key "$PRIVATE_KEY" \
  --broadcast
```

#### 3. Option B — Deployment script

Create `script/DeploySimpleStorage.s.sol`:

```solidity theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Script} from "forge-std/Script.sol";
import {SimpleStorage} from "../src/SimpleStorage.sol";

contract DeploySimpleStorage is Script {
    function run() external returns (SimpleStorage) {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(deployerPrivateKey);
        SimpleStorage c = new SimpleStorage();
        vm.stopBroadcast();
        return c;
    }
}
```

Run it:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
source .env
forge script script/DeploySimpleStorage.s.sol:DeploySimpleStorage \
  --rpc-url "$RPC_URL" \
  --broadcast
```

#### Agung note

If gas estimates are too low on Agung, append:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
--gas-estimate-multiplier 300 --slow
```

## Post-Deployment Validation

**Verify Deployment on Blockchain Explorer:**

* Use the [peaq](https://peaq.subscan.io/) or [agung](https://agung-testnet.subscan.io/) block explorer to search for your transaction hash or the deployed smart contract address.
* Confirm that your contract is successfully deployed.

After confirming that the transaction has been submitted and the smart contract address is valid, please follow our next tutorial which shows how to **interact** with the Deployed Contract.
