# Deploying a Contract Using Foundry

Foundry is a Rust-based Ethereum development tool that enables developers to manage Solidity dependencies, compile and test smart contracts, deploy them, and interact with the blockchain through a command-line interface (CLI).

This guide outlines the process of building a Wallet dApp using Foundry and the dKargo Warehouse Testnet.

{% hint style="info" %}
When deploying a contract on any blockchain, the native token of that chain is required to pay gas fees. This applies to dKargo Chain as well. Before deploying on the dKargo testnet (Warehouse), developers can obtain $DKA testnet tokens via the faucet.
{% endhint %}

## STEP 1 - Get Started with Foundry

To install Foundry, run the following command:

Installing Foundry is simple.

* Linux or MacOS

```
curl -L <https://foundry.paradigm.xyz> | bash foundryup
```

* Windows

```
curl --proto '=https' --tlsv1.2 -sSf <https://sh.rustup.rs/> | sh cargo install --
git <https://github.com/foundry-rs/foundry> foundry-cli anvil --bins --locked
```

## STEP 2 - Set Up Foundry Project

After installing Foundry, the next step is to initialize a new project.

```bash
mkdir helloDka
cd helloDka
forge init .
```

Below is an example of the Foundry project folder structure.

```bash
/helloDka
├── README.md
├── foundry.toml
├── lib
|  └── forge-std
├── script
|  └── Counter.s.sol
├── src
|  └── Counter.sol
└── test
   └── Counter.t.sol
```

## Step 3 - Example Contract: `Counter.sol`

A newly created Foundry project includes a sample contract (<mark style="color:blue;">`counter.sol`</mark>) along with a sample test file by default. The <mark style="color:blue;">`counter.sol`</mark> contract implements a simple function to set the `number` variable.

```jsx
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract Counter {
    uint256 public number;

    function setNumber(uint256 newNumber) public {
        number = newNumber;
    }

    function increment() public {
        number++;
    }
}

```

## Step 4 - Compiling the Contract

If the contract compiles without errors, it is valid and ready for deployment on Warehouse.

```jsx
forge build
```

## Step 5 - Deploying the Contract on Warehouse

Deploying a contract can be easily completed with a single Forge CLI command.

However, this process requires:

* The Warehouse RPC endpoint
* A private key with sufficient $DKA for transaction fees

Use the provided RPC endpoint URL and ensure the private key is ready before proceeding.

* Warehouse RPC Endpoint : <https://it-full.dknote.net>

```jsx
forge create --rpc-url "<https://it-full.dknote.net>" --private-key YOUR_PRIVATE_KEY  src/Counter.sol:Counter
```

Upon successful execution, the following response will be displayed:

<figure><img src="https://content.gitbook.com/content/im6M65ZKMXUcKE8zSRGC/blobs/w9dJdHOKy4YUcYXOj4Ol/%E1%84%8F%E1%85%A5%E1%86%AB%E1%84%90%E1%85%B3%E1%84%85%E1%85%A2%E1%86%A8%E1%84%90%E1%85%B3%E1%84%87%E1%85%A2%E1%84%91%E1%85%A91.png" alt=""><figcaption></figcaption></figure>

The contract has been successfully deployed on dKargo’s Warehouse testnet.

Copy the contract address specified in "Deployed to", and use it to search for deployment details on [dScanner](https://warehouse.dscanner.io/).
