Solidity
here you will get byte code and abi code
to get the byte code you have to go to the
search for byte code to open code
and 0x hexadecimal
Bytecode to Opcode Disassembler
https://etherscan.io/opcode-tool
The Ethereum Virtual Machine is the software platform that developers can use to create decentralized applications (DApps) on Ethereum
we can use injected we3 for the deploy a contract or run a transcation
koi bhi value maae change nahi karta haa to vo view khala ta haa
pragma solidity ^0.5.0;
contract Details{
string name;
uint age;
constructor() public {
name = "Goku";
age = 24;
}
function getname() view public returns(string memory){
return name;
}
function getage() view public returns(uint){
return age;
}
function setage() public {
age = age+1;
}
}
String ka lia string memor is nessesary
koi bhi variable like (uint,string) contract scope ka under likha ho usi ko state variable khata haa
State varible jaitna use karo ga utna gas fee dena padta haa
Solidity mae none ya null ka consept nahi haa
state variable store in contract storage
we can assign value to state variable in three ways
like with the help of constructor , by creating a function and directly
contract Variables{
uint public age = 100;
uint public num;
// constructor() public{
// age = 200;
// }
function setAge() public {
age = 400;
}
}
Local Variable
Local variable store data in stack
local variable are those who is declear under the function body
pure ka matlab na toa ya hamara state variable mae change la raha ha na toa ya read kar raha haa
pragma solidity ^0.5.0;
contract Local{
function getdata() pure public returns(uint){
uint age = 20;
return age;
}
}
string by default storage mae store hota haa toa isa bachna ka lia hum memory ka istamal karta haa
string memory
to ya store hota haa humara memory na toa stack mae or na toa storage mae
string memory name = "biplav";
setter method mae hum age ka value change karraha haa that's why hum pure ya view ko nahi use karanga
Argument
we can pass argument with the help of setter function
pragma solidity ^0.5.0;
contract Local{
uint age = 20;
function getter() public view returns(uint){
return age;
}
function setter(uint newage ) public{
age = age+newage;
}
}
agar hum public lika toa huma alag sa getter function banana ke zarurat nahi haa
yae automatticaly ake getter function bna dega
view mae read karag toa iselia koi problem nahi haa
but yaha par hum pure use nahi karsakta
pure ko hum vaha use karsakta haa jaha pae hum state variable ko read and write nahi karaha haa
Ise example pae hum na toa state variable ko read karaha haa na toa hum
write karaha ha local variable bna lya haa
view dono he condition mae suitable haa
Constructor
Constructor is a special type of Function which execute only one time when we create contarct
Use of Constructor
mainly wecan use constructor by 2 ways
1)when we have to Initialise the state variable
2)when we have to declare contract ka owner
pragma solidity ^0.5.0;
contract Local{
uint public count; // public likh na sa apena ape ake gutter function bnadega
constructor(uint number) public{
count = number;
}
}
int :- ise ka under hum +ive and -ive both value desakta haa
uint :- iska under hum sirf +ive value desakta haa
Fixd Size Array
Change array ka value with setter function
contract Local{
uint[4] public arr = [10,20,30,40];
function setter(uint index,uint value) public {
arr[index] = value;
}
}
This is how we can change the array ka value in any index
Array length (Array ka length )
pragma solidity ^0.5.0;
contract Local{
uint[4] public arr = [1,2,3,4];
function length() public view returns(uint){
return arr.length;
}
}
uint256
Low level interaction
jahapa array ka size fix na ho
pragma solidity ^0.5.0;
contract Local{
uint[] public arr;
function setfunction(uint val) public {
arr.push(val);
}
}
value dalta jayanga or array index ka sath banta jaya ga
10,20,30,40
yae Arraylist ka jasa haaa
pop remove last element from array
Byte Array in fixed-size Array
Hexa decimal (0x)
contract Local{
bytes3 public b3; // 0x0000 hamasha multiply by 2
bytes2 public b2;
function size() public{
b3 = 'abc';
b2 = 'he';
}
}
bytes3: 0x616200
Here we use bytes as data type and result is the character value
or say Asci values
byte array is immutable
contract Local{
//dynamic bytes type array
bytes public b3 = "abc";
function change() public {
b3.push('d');
}
function check(uint i) public view returns (bytes1){
return b3[i];
}
function length() public view returns(uint){
return b3.length;
}
}
contract Local{
//dynamic bytes type array
uint[3] public arr; //state variable
uint public count;
function loop() public {
while(count<arr.length){
arr[count] = count;
count++;
}
}
}
for loop
contract Local{
uint[4] public arr;
uint public count;
function loop() public {
for(count;count<arr.length;count++){
arr[count] = count;
}
}
}
Do while Loop
contract Local{
uint[4] public arr;
uint public count;
function loop() public {
do{
arr[count] = count;
count++;
}while(count<arr.length);
}
}
IF else
contract Local{
function condition(uint value) public pure returns (string memory){
string memory val;
if(value>0){
val= "greater than 0";
}else if(value==0){
val = "equal to 0";
}else{
val = "less than 0";
}
return val;
}
}
Boolean (true or false)
contract Local{
bool public name; //by default bool mae false pada rahata haaa
function check(uint a) public returns(bool) {
if(a>0){
name = true;
}else{
name = false;
}
}
}
Structure data-type (struct)
pragma solidity ^0.8.0;
struct student{
uint number;
string name;
}
contract Local{
student public s1;
constructor(uint _number, string memory _name) public {
s1.number = _number;
s1.name = _name;
}
}
Change karna ka lia
pragma solidity ^0.8.0;
struct student{
uint number;
string name;
}
contract Local{
student public s1;
constructor(uint _number, string memory _name) public {
s1.number = _number;
s1.name = _name;
}
function change(uint _number, string memory _name) public {
student memory news1 = student({
number : _number,
name : _name
});
s1 = news1;
}
}
Enum
contract Local{
mapping(uint=>string) public roll_no;
function setter(uint keys,string memory value) public {
roll_no[keys]= value;
}
}
Diffrent between mapping and array
array sequensial means ake ka bade ake
Mapping with structure(struct)
contract Local{
struct Student {
uint number;
string name;
}
mapping(uint=>Student) public data;
function setter(uint _roll,uint _number,string memory _name) public{
data[_roll] = Student(_number,_name);
}
}
contract Local{
string[] public data = ['ben','ten','biden'];
function memo() public view{
string[] memory s1 = data;
s1[0] = "akshy";
}
function stor() public {
string[] storage s1 = data;
s1[0] = "akshy";
}
}
They are build in variable with the help of this we can know many things like sender address,time ,etc
contract Local{
function getter() public view returns(uint block_no,uint timestamp,address msgSender){
return (block.number,block.timestamp,msg.sender);
}
}
https://www.epochconverter.com/
ja par bhi ether tansfer karna ho usea function mae hum payable use karta haa
address is also a datatype of solidity
this keyword ka matalab particular isea addres sa lana haa ya ise funcyion sa feth karna haa
sending ether to contract
contract Local{
function payeth() public payable{
}
function getbalance()public view returns(uint){
return address(this).balance;
}
}
contract Local{
address payable user = payable(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2);
function payeth() public payable{
}
function getbalance()public view returns(uint){
return address(this).balance;
}
function sendeth() public{
user.transfer(1 ether);
}
}
contract Local{
function f1() public pure returns(uint){
return 1;
}
function f2() private pure returns(uint){
return 2;
}
function f3() internal pure returns(uint){
return 3;
}
function f4() external pure returns(uint){
return 4;
}
}
with in the contract
contract Local{
function f1() public pure returns(uint){
return 1;
}
function f2() private pure returns(uint){
return 2;
}
function f3() internal pure returns(uint){
uint x = f1();
return 3;
}
function f4() external pure returns(uint){
return 4;
}
}
Derivd contract
f4(),f2() wala error dega
pragma solidity ^0.8.0;
contract Local{
function f1() public pure returns(uint){
return 1;
}
function f2() private pure returns(uint){
return 2;
}
function f3() internal pure returns(uint){
uint x = f1();
return 3;
}
function f4() external pure returns(uint){
return 4;
}
}
contract c{
Local obj = new Local();
uint public cx = obj.f1();
}
creating object
f2(),f3() will give error
Comments
Post a Comment