# Deploy Your First Contract (/docs/cookbook/deploy-first-contract)

import { Step, Steps } from 'fumadocs-ui/components/steps';
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

A hands-on guide to deploying your first smart contract on RISE. You'll create a simple Counter contract that stores and increments a number.

## What You'll Build

A basic Counter contract with two functions:

* `count` - A public variable to read the current count
* `increment()` - Increments the count by 1

## The Contract

This is the contract you'll deploy:

```solidity title="Counter.sol"
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

contract Counter {
    uint256 public count;

    function increment() external {
        count++;
    }
}
```

Simple, right? Now let's deploy it using your preferred tool.

## Choose Your Tool

<Tabs items={['Remix', 'Foundry', 'Hardhat']}>
  <Tab value="Remix">
    ## Deploy with Remix

    The easiest way to get started - no installation required!

    ### Prerequisites

    * A crypto wallet (MetaMask or Rabby) with RISE Testnet configured
    * Testnet ETH from the [RISE Faucet](https://faucet.testnet.riselabs.xyz/)

    <Steps>
      <Step>
        ### Open Remix IDE

        Go to [remix.ethereum.org](https://remix.ethereum.org) in your browser.
      </Step>

      <Step>
        ### Create the Contract

        1. In the File Explorer (left sidebar), create a new file called `Counter.sol`
        2. Copy and paste the Counter contract code shown above
        3. Save the file (Ctrl+S or Cmd+S)
      </Step>

      <Step>
        ### Compile

        1. Click the **Solidity Compiler** tab in the left sidebar
        2. Select compiler version `0.8.0` or higher
        3. Click **Compile Counter.sol**

        You should see a green checkmark when compilation succeeds.

        <Callout type="info">
          Enable **Auto compile** to automatically compile as you make changes.
        </Callout>
      </Step>

      <Step>
        ### Deploy to RISE

        1. Click the **Deploy & Run Transactions** tab
        2. In **Environment**, select **Injected Provider - MetaMask**
        3. Your wallet will prompt you to connect - click **Connect**
        4. **Important**: Verify your wallet is on RISE Testnet (Chain ID: 11155931)
        5. Select `Counter` in the **Contract** dropdown
        6. Click **Deploy**
        7. Confirm the transaction in your wallet
      </Step>

      <Step>
        ### Interact with Your Contract

        After deployment, expand your contract under **Deployed Contracts**:

        * Click the blue `count` button to read the current value (starts at 0)
        * Click the orange `increment` button to increase the count
        * Click `count` again to see the updated value

        Each `increment` call requires a transaction confirmation.
      </Step>
    </Steps>

    ### View on Explorer

    Copy the contract address from Remix and view it on the [RISE Testnet Explorer](https://explorer.testnet.riselabs.xyz).
  </Tab>

  <Tab value="Foundry">
    ## Deploy with Foundry

    Fast, Rust-based toolkit for smart contract development.

    ### Prerequisites

    * Foundry installed ([installation guide](https://book.getfoundry.sh/getting-started/installation))
    * Testnet ETH from the [RISE Faucet](https://faucet.testnet.riselabs.xyz/)

    <Steps>
      <Step>
        ### Create Project

        Initialize a new Foundry project:

        ```bash
        forge init counter-project
        cd counter-project
        ```
      </Step>

      <Step>
        ### Add the Contract

        Replace `src/Counter.sol` with our Counter contract:

        ```solidity title="src/Counter.sol"
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;

        contract Counter {
            uint256 public count;

            function increment() external {
                count++;
            }
        }
        ```
      </Step>

      <Step>
        ### Configure RISE Network

        Update `foundry.toml`:

        ```toml title="foundry.toml"
        [profile.default]
        src = "src"
        out = "out"
        libs = ["lib"]
        solc = "0.8.30"

        [rpc_endpoints]
        rise_testnet = "https://testnet.riselabs.xyz"
        ```
      </Step>

      <Step>
        ### Compile

        Build your contract:

        ```bash
        forge build
        ```
      </Step>

      <Step>
        ### Deploy

        Deploy to RISE Testnet using your private key:

        ```bash
        forge create \
          --rpc-url rise_testnet \
          --private-key 0xYOUR_PRIVATE_KEY_HERE \
          src/Counter.sol:Counter
        ```

        Alternatively, use a keystore for better security:

        ```bash
        forge create \
          --rpc-url rise_testnet \
          --account <keystore-name> \
          src/Counter.sol:Counter
        ```

        <Callout type="info">
          Learn how to create a keystore: [Foundry Keystore Guide](https://book.getfoundry.sh/reference/cast/cast-wallet-import)
        </Callout>

        Save the contract address from the output!
      </Step>

      <Step>
        ### Interact with Your Contract

        Read the count:

        ```bash
        cast call <CONTRACT_ADDRESS> "count()" --rpc-url rise_testnet
        ```

        Increment the count:

        ```bash
        cast send <CONTRACT_ADDRESS> \
          "increment()" \
          --rpc-url rise_testnet \
          --private-key 0xYOUR_PRIVATE_KEY_HERE
        ```

        Read again to see the updated value.
      </Step>
    </Steps>

    ### View on Explorer

    Visit [RISE Testnet Explorer](https://explorer.testnet.riselabs.xyz) and search for your contract address.
  </Tab>

  <Tab value="Hardhat">
    ## Deploy with Hardhat

    Flexible development environment with great tooling support.

    ### Prerequisites

    * Node.js v22 or later
    * Testnet ETH from the [RISE Faucet](https://faucet.testnet.riselabs.xyz/)

    <Steps>
      <Step>
        ### Create Project

        Initialize a new Hardhat project:

        ```bash
        mkdir counter-project
        cd counter-project
        npx hardhat --init
        ```

        When prompted:

        * Select "Hardhat 3 Beta"
        * Choose current directory
        * Select "A minimal Hardhat project"
        * Install dependencies: yes
      </Step>

      <Step>
        ### Add the Contract

        Create `contracts/Counter.sol`:

        ```bash
        mkdir contracts
        ```

        ```solidity title="contracts/Counter.sol"
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.0;

        contract Counter {
            uint256 public count;

            function increment() external {
                count++;
            }
        }
        ```
      </Step>

      <Step>
        ### Configure RISE Network

        Update `hardhat.config.ts`:

        ```typescript title="hardhat.config.ts" {2,11-16}
        import hardhatToolboxViemPlugin from "@nomicfoundation/hardhat-toolbox-viem";
        import { configVariable, defineConfig } from "hardhat/config";

        export default defineConfig({
          plugins: [hardhatToolboxViemPlugin],
          solidity: {
            version: "0.8.30",
          },
          networks: {
            riseTestnet: {
              type: "http",
              url: "https://testnet.riselabs.xyz",
              accounts: [configVariable("RISE_PRIVATE_KEY")],
              chainId: 11155931
            }
          }
        });
        ```
      </Step>

      <Step>
        ### Set Your Private Key

        Store your private key securely:

        ```bash
        npx hardhat keystore set RISE_PRIVATE_KEY
        ```

        Enter your private key when prompted.
      </Step>

      <Step>
        ### Compile

        Compile your contract:

        ```bash
        npx hardhat compile
        ```
      </Step>

      <Step>
        ### Create Deployment Module

        Create the deployment script:

        ```bash
        mkdir -p ignition/modules
        ```

        ```typescript title="ignition/modules/Counter.ts"
        import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

        export default buildModule("CounterModule", (m) => {
          const counter = m.contract("Counter");

          return { counter };
        });
        ```
      </Step>

      <Step>
        ### Deploy

        Deploy to RISE Testnet:

        ```bash
        npx hardhat ignition deploy ignition/modules/Counter.ts --network riseTestnet
        ```

        Save the contract address from the output!
      </Step>

      <Step>
        ### Interact with Your Contract

        You can interact with your contract using Hardhat console:

        ```bash
        npx hardhat console --network riseTestnet
        ```

        Then in the console:

        ```javascript
        const Counter = await ethers.getContractFactory("Counter");
        const counter = await Counter.attach("YOUR_CONTRACT_ADDRESS");

        // Read count
        await counter.count();

        // Increment
        await counter.increment();

        // Read again
        await counter.count();
        ```
      </Step>
    </Steps>

    ### View on Explorer

    Visit [RISE Testnet Explorer](https://explorer.testnet.riselabs.xyz) and search for your contract address.
  </Tab>
</Tabs>

## Next Steps

Congratulations! You've deployed your first contract on RISE. Here's what you can explore next:

<Cards>
  <Card title="Smart Contract Development" href="/docs/builders/smart-contracts" description="Deep dive into smart contract development on RISE" />

  <Card title="Frontend Integration" href="/docs/builders/frontend" description="Connect your contract to a web interface" />

  <Card title="Testing Contracts" href="/docs/builders/quick-start" description="Learn how to write tests for your contracts" />
</Cards>
