Skip to main content

Deploy a contract

Prerequisites

  • A wallet with some testnet ETH on Horizen Testnet

Deploy a contract using Foundry

Foundry is a Rust-based toolset for Ethereum development that helps developers manage dependencies, compile projects, run tests, deploy contracts, and interact with blockchains via the command line interface. Open a terminal and run the following commands to install Foundry:

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

Next we will create a project with Foundry. We will start with the basic Counter contract Foundry provides. Run the following command to create a Foundry project:

forge init hello_horizen && cd hello_horizen

After this we will compile our smart contracts using the following command:

forge build

Next we will deploy the counter contract located at src/Counter.sol using the forge create command. We would also need the RPC_URL and the PRIVATE_KEY of the funded wallet to deploy the contracts. Use the following command to deploy your contracts:

forge create src/Counter.sol:Counter \
--rpc-url https://horizen-testnet.rpc.caldera.xyz/http \
--private-key <YOUR_PRIVATE_KEY>

Deploy a contract using Hardhat

Hardhat is a flexible and extensible development environment for Ethereum software. It helps you write, test, debug, and deploy your smart contracts with ease, whether you’re building a simple prototype or a complex production system.

You can initialize a hardhat project with the following commands

mkdir hardhat-tutorial
cd hardhat-tutorial
npx hardhat --init

And then compile the project using this command

npx hardhat build

In the hardhat.config.ts file, we will need to add configuration for Horizen:

networks: {
horizen: {
type: "http",
url: "https://horizen-testnet.rpc.caldera.xyz/http",
accounts: ["<PRIVATE_KEY>"],
},
},

And then you can use the following command to deploy the Counter smart contract on Horizen testnet

npx hardhat ignition deploy ignition/modules/Counter.ts --network horizen