Foundry

Foundry is a comprehensive toolset for Ethereum development, written in Rust. It aids developers in managing dependencies, compiling projects, running tests, deploying contracts, and interacting with blockchains via a command-line interface. Foundry's robust capabilities streamline the development process, making it easier to work with Ethereum and other compatible networks.

Additionally, Foundry integrates seamlessly with Caldera's Ethereum API, enabling direct deployment of smart contracts onto the Caldera network.

Get Started with Foundry

  1. Install Foundry

Linux or macOS

To install Foundry on Linux or macOS, use the following commands:

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

Windows

For Windows, first install Rust, then install Foundry:

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
  1. Create a Project Initialize a new Foundry project with:

forge init foundry
  1. Navigate to the Source in the project and create your smart contrac

cd src
touch MyToken.sol
  1. Add your smart contract code or use the sample contract below:

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor(uint256 initialSupply) public ERC20("MyToken", "TKN") {
        _mint(msg.sender, initialSupply);
    }
}
  1. Install OpenZeppelin Contracts as a Dependency To add OpenZeppelin contracts as a dependency, run:

forge install OpenZeppelin/openzeppelin-contracts
  1. Compile Contract

forge build

Deploying Your Smart Contract

Deploying a contract with Forge is a simple process that can be done with a single command. However, it requires an RPC endpoint, a private key that has funds, and any arguments for the constructor of the contract.

For example, the MyToken.sol contract requires an initial supply of tokens to be specified in its constructor, so the command to deploy it on a network will include the argument of 100.

To deploy the MyToken.sol contract, use the command that corresponds to the Caldera chain's RPC URL while running the forge create command:

forge create --rpc-url "https://sovruntest.rpc.caldera.xyz/http" \
--constructor-args 100 \
--private-key YOUR_PRIVATE_KEY \
src/MyToken.sol:MyToken

Last updated