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 version pragma solidity ^0.5.0; // create contract contract Example { // create state variable string str = "Edpresso"; // create function function getStr() public view returns(string memory) { return str; } }
^0.5.0
.contract
named Example
.str
.getStr()
that returns the value of str
.RELATED TAGS
CONTRIBUTOR
View all Courses