Deploy Smart Contracts with Foundry

We’ll create a simple SplitWise app, a contract where friends can track and settle debts.

Prerequisites

  • Install Foundry:

    curl -L <https://foundry.paradigm.xyz> | bash
    foundryup
  • Node.js & npm (for optional frontend)

  • Hela Node/Web3 Gateway running locally or using testnet RPC URL

  • Wallet (Metamask) configured to connect to Hela RPC

Check the version:

forge --version

Initialize Foundry Project:

Let’s create a new project:

forge init hello-hela
cd hello-hela

Inside this folder, you now have:

  • src/ → your contracts

  • test/ → your tests

Write the Smart Contract:

We’ll create a simple SplitWise app, a contract where friends can track and settle debts.

Create :(src/SplitWise.sol)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract SplitWise {
    mapping(address => mapping(address => int256)) public debts;

    event ExpenseAdded(address indexed payer, address indexed to, uint256 amount);
    event DebtCleared(address indexed from, address indexed to, uint256 amount);

    // Record an expense
    function addExpense(address friend, uint256 amount) public {
        debts[friend][msg.sender] -= int256(amount);
        debts[msg.sender][friend] += int256(amount);

        emit ExpenseAdded(msg.sender, friend, amount);
    }

    // Check balance between two friends
    function checkBalance(address friend) public view returns (int256) {
        return debts[msg.sender][friend];
    }

    // Clear a debt
    function clearDebt(address friend, uint256 amount) public {
        require(debts[msg.sender][friend] >= int256(amount), "Not enough debt!");
        debts[msg.sender][friend] -= int256(amount);
        debts[friend][msg.sender] += int256(amount);

        emit DebtCleared(msg.sender, friend, amount);
    }
}

Write a Simple Test (test/SplitWise.t.sol)

Tests are super important to confirm things work before spending gas.

pragma solidity ^0.8.9;

import "forge-std/Test.sol";
import "../src/SplitWise.sol";

contract SplitWiseTest is Test {
    SplitWise splitwise;
    address alice = address(1);
    address bob = address(2);

    function setUp() public {
        splitwise = new SplitWise();
    }

    function testAddExpense() public {
        vm.prank(alice);
        splitwise.addExpense(bob, 100);

        int256 balance = splitwise.checkBalance(bob);
        assertEq(balance, 100);
    }
}

Run the tests:

forge test

Deploy to HeLa

Open foundry.toml and add your Hela testnet endpoint:

[rpc_endpoints]
hela = "<https://rpc.testnet.hela.xyz>"  # replace with actual endpoint

Deploy with:

forge create --rpc-url hela --private-key <YOUR_PRIVATE_KEY> src/SplitWise.sol:SplitWise

Interact with Your Contract

  • Add an expense:

    cast send <CONTRACT_ADDRESS> "addExpense(address,uint256)" <FRIEND_ADDR> 100 --rpc-url hela --private-key <KEY>
    
  • Check balance:

    cast call <CONTRACT_ADDRESS> "checkBalance(address)" <FRIEND_ADDR> --rpc-url hela
    

You’ll see a number:

  • Positive → your friend owes you

  • Negative → you owe them

Support :

If you encounter any issues during setup or require assistance, please join the HeLa Developer Community for direct support and guidance.

Last updated