Join our
Discord!
LogoLogo
SupraScan ExplorerStarKey WalletDiscord
EVM
  • Network
  • Oracles
  • Automation
  • SupraNova
  • Guides
EVM
  • Overview
  • Getting Started
    • Remix IDE
      • Fund Your Wallet
      • Connect StarKey Wallet to Remix
      • Guide to Deploy Smart Contract
    • Hardhat
      • Getting Private Key from StarKey
      • Create Hardhat Project
      • Write Smart Contract
      • Deploying Smart Contract
    • Foundry
      • Getting Private Key from StarKey
      • Create Foundry Project
      • Write Smart Contract
      • Deploying Smart Contract
    • Your First Solidity Contract
  • Network Information
Powered by GitBook
On this page
  • Create a Smart Contract File
  • Create a Deployment Script
Edit on GitHub
  1. Getting Started
  2. Foundry

Write Smart Contract

Create a Solidity contract to store and retrieve data, then set up a deployment script to automate deployment on SupraEVM using Foundry.


Create a Smart Contract File

Set up the SimpleStorage.sol file in the src directory to define a basic Solidity smart contract that allows storing and retrieving a uint256 value on SupraEVM.

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

contract SimpleStorage {
    uint256 public storedData;

    function set(uint256 x) public {
        storedData = x;
    }

    function get() public view returns (uint256) {
        return storedData;
    }
}

Create a Deployment Script

Write a deployment script in the script directory (DeploySimpleStorage.sol) to automate smart contract deployment on SupraEVM using Foundry’s scripting tools.

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

import "forge-std/Script.sol";
import "../src/SimpleStorage.sol";

contract DeploySimpleStorage is Script {
    function run() external {
        uint256 privateKey = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(privateKey);
        new SimpleStorage();
        vm.stopBroadcast();
    }
}
PreviousCreate Foundry ProjectNextDeploying Smart Contract