# How to deploy smart contract using Foundry on Shardeum?

By [@HamedHamede5](https://paragraph.com/@hamedhamede5) · 2023-02-23

---

Smart contracts are self-executing contracts with the terms of the agreement between buyer and seller being directly written into lines of code. They are stored on a decentralized blockchain network, which makes them transparent, tamper-proof, and highly secure. In this blog, we will discuss how to deploy a smart contract using Foundry on Shardeum.

What is Foundry?

Foundry is an open-source tool that enables developers to build, test, and deploy smart contracts on various blockchain networks. It is a part of the Shardeum ecosystem, which is a platform that provides a suite of blockchain tools to developers.

Why use Foundry on Shardeum?

Foundry is an excellent choice for deploying smart contracts on Shardeum because it is highly customizable, easy to use, and it supports various blockchain networks. Shardeum provides developers with a suite of tools that enable them to build decentralized applications (dApps) on various blockchain networks. By using Foundry on Shardeum, developers can easily deploy their smart contracts on the Shardeum network and leverage its benefits, such as high security, transparency, and immutability.

Steps to deploy a smart contract using Foundry on Shardeum:

Step 1: Install Foundry

To install Foundry, you need to have Node.js and npm (Node Package Manager) installed on your computer. Once you have installed Node.js and npm, run the following command in your terminal to install Foundry:

    javaCopy codenpm install -g @shardeum/foundry
    

Step 2: Create a new project

To create a new project using Foundry, run the following command in your terminal:

    luaCopy codefoundry create
    

This will create a new project with the following structure:

    bashCopy code.
    ├── contracts/
    │   └── Example.sol
    ├── migrations/
    │   └── 1_deploy_example.js
    └── test/
        └── example.js
    

The `contracts` folder contains the smart contract code, the `migrations` folder contains the deployment scripts, and the `test` folder contains the test scripts.

Step 3: Write the smart contract code

In the `contracts` folder, you will find a file named `Example.sol`. This is a sample smart contract that has been created for you. You can modify this file or create a new file with your smart contract code.

Here's an example of a simple smart contract that stores a value:

    javaCopy code// SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;
    
    contract MyContract {
        uint256 private value;
    
        function setValue(uint256 _value) public {
            value = _value;
        }
    
        function getValue() public view returns (uint256) {
            return value;
        }
    }
    

This contract has a private variable `value` and two functions, `setValue` and `getValue`. The `setValue` function sets the value of the `value` variable, and the `getValue` function returns the value of the `value` variable.

Step 4: Write the deployment script

In the `migrations` folder, you will find a file named `1_deploy_example.js`. This file contains a sample deployment script that deploys the `Example` contract.

Here's an example of a simple deployment script:

    javascriptCopy codeconst Example = artifacts.require("Example");
    
    module.exports = function (deployer) {
      deployer.deploy(Example);
    };
    

This script imports the `Example` contract and deploys it using the `deploy` function.

Step 5: Deploy the smart contract

To deploy the smart contract, run the following command in your terminal:

    Copy codefoundry deploy
    

This command will compile the smart contract code, run the deployment.

---

*Originally published on [@HamedHamede5](https://paragraph.com/@hamedhamede5/how-to-deploy-smart-contract-using-foundry-on-shardeum)*
