Solidity
language and deploy using Remix IDE, Hardhat, or Foundry. By understanding the inner workings of these
contracts and how they operate on a decentralized network, you’ll be well-equipped to build robust and efficient applications. By the end of this guide,
you’ll have developed a fully functional smart contract, ready for deployment on the peaq network.
SimpleStorage.sol
(.sol
being the standard extension for Solidity code).
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
^
symbol indicates compatibility with versions 0.8.0 and above (up to but not including 0.9.0).contract SimpleStorage { … }
uint256 private data;
uint256
represents the variable type. In this particular case it is an unsigned
integer that can hold large non-negative numbers. The identifier private
restricts the access of the variable within the contract only.function set(uint256 _data) public { … }
set
function here allows users to update the value of data
. The keyword public
means that the function is
accessible to everyone (any address can call it). The keyword parameter _data
is used to represent the data a user sent to the contact. By convention these variables start with an underscore.function get() public view returns (uint256) { … }
data
that is stored on the blockchain. The keyword view
is used to restrict the function to be read-only so it does not modify the
state of the chain. returns
specifies what type of value the function will return to the user..env
File.env
file to store sensitive data..env
file:rpc_url
with the RPC URL of the peaq/agung test network.wallet_private_key
with your wallet’s private key.hardhat.config.js
file to include the network configurationcontracts/
folder, create a file named SimpleStorage.sol
.foundry.toml
foundry.toml
in the project root:
evm_version
is set to london
for peaq-like networks, due to the fork used on the substrate-based network.
src/SimpleStorage.sol
and paste the same contract used above:
SimpleStorage.sol
instead.