Skip to content

Instantly share code, notes, and snippets.

@bhagat9198
Created December 25, 2021 08:07
Show Gist options
  • Save bhagat9198/724f91742dda0e706d9f4fa8e417b9c1 to your computer and use it in GitHub Desktop.
Save bhagat9198/724f91742dda0e706d9f4fa8e417b9c1 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// defined the versionof the solidity to be used
pragma solidity ^0.4.24;
// defining the smart contract -
// smart contract is the code taht gets executed on blockchan. It is like a microservice and will be asscebile to everyone on the blockchain. users will able to see and use it. they will able to read and write data with it.
// hence, it will be public.
// looks like the class
contract myContract {
// task: read and write the value
// solidity is statically typed lang.
// declaring the state value
// 'value': its value which entire contract will know, hence its global to it.
// which means that whatever value we are writting to it, it is getting stored in blockchain as it will stored on blockchain. but same is not true for a varable which we decalre within a function as it will just have local scope.
string value;
// readingthe value : basic way to do
// 'public' : giving the visibility that anyone can call it, it will also have global scope
// 'view' : to remove the error
function get() public view returns(string) {
return value;
}
// write the value
// giving public visibilty, anyone can set the value
function set(string _val) public {
value = _val
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment