A Solidity contract is a block of code that contains functions and state variables. It is stored on a specific address on the Ethereum blockchain.
Every Solidity code starts with the pragma
version. The pragma
version specifies the version of the compiler that the code should use.
pragma solidity ^0.5.0;
To create a contract, we use the contract
keyword followed by the contract name. Inside the {}
brackets, we create the variables and functions.
contract contractName {// code}
Let’s see how to create a contract in Solidity.
// declare pragma versionpragma solidity ^0.5.0;// create contractcontract Example {// create state variablestring str = "Edpresso";// create functionfunction getStr() public view returns(string memory) {return str;}}
^0.5.0
.contract
named Example
.str
.getStr()
that returns the value of str
.