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!
Table of Contents
Section titled “Table of Contents”- Preparing a development environment
- Deploying a smart contract
- Testing the smart contract
Preqrequisites
Section titled “Preqrequisites”-
Prepare Dev Environemnt
Section titled “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:
Terminal window foundryup -
Create a New Foundry Project
Section titled “Create a New Foundry Project”Run the following in your terminal:
Terminal window forge init my-first-contract -
Modify Foundry Configuration
Section titled “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" -
The Smart Contract
Section titled “The Smart Contract”Smart contracts are created under the
src
folder. There is already aCounter.sol
contract in the project located atsrc/Counter.sol
.// SPDX-License-Identifier: UNLICENSEDpragma 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 publicread
function. The write functions aresetNumber
andincrement
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. -
Compile the Smart Contract
Section titled “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 theout
folder.Terminal window forge compile -
Prepare Signer for Deployment
Section titled “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:
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-deployerCopy 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).
-
Deploy the Smart Contract
Section titled “Deploy the Smart Contract”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 --legacyA successful deployment should look something like this:
Terminal window Enter keystore password:Deployer: 0x63a38D694de837dDF765f9b2704814275586D812Deployed to: 0x4A435f6E471f773173774E860EBDcd17B132a2b4Transaction hash: 0x3f6cc66e860cb82a6a62e3f5181c401e5558d60d622a9157437002e16c1ce488 -
Verify your Smart Contract
Section titled “Verify your Smart Contract”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/apiTerminal window # The following is an example of what the full verification request looks likeforge 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# OutputStart verifying contract `0x4A435f6E471f773173774E860EBDcd17B132a2b4` deployed on 1444673419Contract [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
Section titled “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. 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!