# 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="/files/RMsLI4PmQAsgBBj4H1IZ" 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/).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dkargo.io/docs2-eng/deploy-contract/deploying-a-contract-using-foundry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
