Develop & Deploying your first Ethereum Smart Contract with Solidity and python in VSCode on Debian and Ubuntu-based distributions
Let’s start with the basics.
What is a Smart Contract?
“Smart contracts are a type of Ethereum account. This means they have a balance and they can send transactions over the network. However they’re not controlled by a user, instead they are deployed to the network and run as programmed. User accounts can then interact with a smart contract by submitting transactions that execute a function defined on the smart contract. Smart contracts can define rules, like a regular contract, and automatically enforce them via the code. Smart contracts cannot be deleted by default, and interactions with them are irreversible.” ~ Ethereum.org
What is Solidity?
“Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs which govern the behavior of accounts within the Ethereum state.” ~ docs.soliditylang.org
Procedure:
- Setup VSCode. If you haven’t, click here.
- Integrate python in VSCode for deployment. If you haven’t, click here.
- Integrate Solidity for compiling. If you haven’t click here.
- Creating smart Contract:
I am creating a smart contract file named “simpleStorage.sol”.
// SPDX-License-Identifier: MIT;//define solidity version// pragma solidity >=0.6.0 <0.9.0;// pragma solidity 0.6.0;//specific// pragma solidity ^0.6.0;//every version of 0.6pragma solidity ^0.8.0;// defining contract like a lass in oopcontract SimpleStorage{//data types// uint256 favouriteNumber=5;// uint favouriteNumber1=5;// bool favouriteBool = true;// string favouriteString="abc";// int256 favouriteInt=-5;// address favouriteAddress= 0x7EF7E075edB1801578A0aedb749DdE3644D50D65;//eth a/c address// bytes32 favouriteBytes="cat";//32 max bytes in stringuint256 favouriteNumber;//=0// uint256 public favouriteNumber;//=0 to see fvrt number// uint256 favouriteNumber;//=0 to see fvrt numberfunction store(uint256 _favouriteNumber) public {favouriteNumber=_favouriteNumber;}// view functions //getterfunction retrieve() public view returns(uint256){return favouriteNumber;}//view and pure are non-stage changing functions// view- only read thats why they are blue//statereading//retrns//pure to do maths //no returns //no state redaing// function retrievepure(uint256 favouriteNumber) public pure {// favouriteNumber + favouriteNumber;// }// STRUCTS:WHAT IF WE WANT A GROUP OF PEOPLE AND STORE THEIR FVRT NUMBERstruct People{uint256 favouriteNumber;string name;}// People public person = People({favouriteNumber:2, name:"abc"});// ..storing variables in solidity works in numberic index fashion// to create whole list of People// A R R A YPeople[] public people;//dynamic// People[10] public people;//fixedfunction addPerson(string memory _name, uint256 _favouriteNumber) public {// people.push(People({favouriteNumber:_favouriteNumber, name:_name}));people.push(People(_favouriteNumber,_name));nameToFvrtNum[_name]=_favouriteNumber;}//to access array use index//ways to store info in solidity:1-memory ,2-storage// memory data will only be stored during execution of function /contract//data will exist even after execution//String is actuallt an array of bytes//M A P P I N G S(dictionary)//what if we looking for specific personmapping(string => uint256) public nameToFvrtNum;}//deployin to a live network:mainnetor testnet// we are using rinkby to deploy
INcomplete ;( gonna complete later.