Skip to main content
This introduction is perfect for most developers or programmers who have some basic experience writing code and that are interested in building decentralized applications or dApps on SKALE! If you run into any trouble or have questions throughout this guide or at any point in time when building on SKALE, head over to the SKALE Discord for support!

Table of Contents

  1. Preparing a development environment
  2. Deploying a smart contract
  3. Testing the smart contract

Preqrequisites

  1. Prepare Dev Environemnt

    • Ensure you have Rust installed on your machine.
    • Install Foundry if you do not have it installed on your machine
    Run the following in your terminal to install the development tools:
    foundryup
    
  2. Create a New Foundry Project

    Run the following in your terminal:
    forge init my-first-contract
    
  3. Modify Foundry Configuration

    Update the foundry.toml file to add SKALE Europa Testnet
    [profile.default]
    src = "src"
    out = "out"
    libs = ["lib"]
    
    # SKALE Europa Testnet Configuration
    [rpc_endpoints]
    skale_testnet="https://testnet.skalenodes.com/v1/juicy-low-small-testnet"
    
  4. The Smart Contract

    Smart contracts are created under the src folder. There is already a Counter.sol contract in the project located at src/Counter.sol.
    // SPDX-License-Identifier: UNLICENSED
    pragma solidity ^0.8.13;
    
    contract Counter {
        uint256 public number;
    
        function setNumber(uint256 newNumber) public {
            number = newNumber;
        }
    
        function increment() public {
            number++;
        }
    }
    
    This smart contract has two public write functions and 1 public read function. The write functions are setNumber and increment which allow the sender to set any number of increment by one (1) respectivley. The read function allows anyone to read the current number set in the contract.
  5. Compile the Smart Contract

    Compilation is the process of taking Solidity smart contracts in the src folder and compiling them to EVM compatible bytecode and ABIs which offchain programs use to interact with the smart contract. You can find the output of the compilation process in the out folder.
    forge compile
    
  6. Prepare Signer for Deployment

    This tutorial uses the Foundry Keystore for increased security. You can optionally fill up your own wallet with sFUEL, and set the private key in commands using —private key [your-private-key], however, this is not recommended. Start by creating a new keystore:
    cast wallet import skale-deployer --private-key $(cast wallet new | grep 'Private key:' | awk '{print $3}')
    
    The above command:
    • Generates a new private key
    • Imports the private key into a keystore file named skale-deployer
    • Prints the address of the newly created wallet to the console
    You can reprint the address at any time using:
    cast wallet address --account skale-deployer
    
    Copy the address from your console and head over to the sFUEL Station. Input the address, toggle testnet, and fill up on Europa Testnet (the blue one).
  7. Deploy the Smart Contract

    To deploy the Counter.sol smart contract, run the following and enter your keystore deployer password:
    forge create src/Counter.sol:Counter --account skale-deployer --rpc-url skale_testnet --broadcast --legacy
    
    A successful deployment should look something like this:
    Enter keystore password:
    Deployer: 0x63a38D694de837dDF765f9b2704814275586D812
    Deployed to: 0x4A435f6E471f773173774E860EBDcd17B132a2b4
    Transaction hash: 0x3f6cc66e860cb82a6a62e3f5181c401e5558d60d622a9157437002e16c1ce488
    
  8. Verify your Smart Contract

    To verify your smart contract, run the following in your terminal:
    forge verify-contract \
        --rpc-url skale_testnet \
        [address] \
        src/Counter.sol:Counter \
        --verifier blockscout \
        --verifier-url https://juicy-low-small-testnet.explorer.testnet.skalenodes.com/api
    
    # The following is an example of what the full verification request looks like
    forge verify-contract \
        --rpc-url skale_testnet \
        0x4A435f6E471f773173774E860EBDcd17B132a2b4 \
        src/Counter.sol:Counter \
        --verifier blockscout \
        --verifier-url https://juicy-low-small-testnet.explorer.testnet.skalenodes.com/api
    
    # Output
    Start verifying contract `0x4A435f6E471f773173774E860EBDcd17B132a2b4` deployed on 1444673419
    
    Contract [src/Counter.sol:Counter] "0x4A435f6E471f773173774E860EBDcd17B132a2b4" is already verified. Skipping verification.
    
    # You can validate the deployment here: https://juicy-low-small-testnet.explorer.testnet.skalenodes.com/address/0x4A435f6E471f773173774E860EBDcd17B132a2b4
    

Next Steps

Great work! You successfully deployed your first contract to SKALE making use of the zero gas fees and a number of popular tools.

Continue Learning

Resources

Welcome to the SKALEVerse!