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.

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.

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.

mkdir helloDka
cd helloDka
forge init .

Below is an example of the Foundry project folder structure.

/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 (counter.sol) along with a sample test file by default. The counter.sol contract implements a simple function to set the number variable.

// 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.

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

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:

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.

Last updated