Skip to content

Solidity Intro & Quickstart

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!

  1. Preparing a development environment
  2. Deploying a smart contract
  3. Testing the smart contract
    • 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:

    Terminal window
    foundryup
  1. Run the following in your terminal:

    Terminal window
    forge init my-first-contract
  2. 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"
  3. 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.

  4. 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.

    Terminal window
    forge compile
  5. 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:

    Terminal window
    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:

    Terminal window
    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).

  6. To deploy the Counter.sol smart contract, run the following and enter your keystore deployer password:

    Terminal window
    forge create src/Counter.sol:Counter --account skale-deployer --rpc-url skale_testnet --broadcast --legacy

    A successful deployment should look something like this:

    Terminal window
    Enter keystore password:
    Deployer: 0x63a38D694de837dDF765f9b2704814275586D812
    Deployed to: 0x4A435f6E471f773173774E860EBDcd17B132a2b4
    Transaction hash: 0x3f6cc66e860cb82a6a62e3f5181c401e5558d60d622a9157437002e16c1ce488
  7. To verify your smart contract, run the following in your terminal:

    Terminal window
    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
    Terminal window
    # 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

Great work! You successfully deployed your first contract to SKALE making use of the zero gas fees and a number of popular tools. Head over to the Foundry documentation to learn more about the tool, join us in Discord to start asking questions, or start hacking away on your smart contracts! Welcome to the SKALEVerse!