refrence ==> these store the refrence to the exact data. e.g. array that refrence to exact element of array.
here in this snap shot we can use the require multiple time in these function but that would be redundant in nature
these are the function that call once when we deploy the smartcontract. mostly used to intialise the variables
1. state variable ==> which store data on blockchain and decalred outside the function. lets take an example of it. also store permanently on blockchain
storage keyword ==> if want to change statevariable infos in function then i need to used storage keyword. just to tell the solidity data will be changed in permanent storage.cant be used in parameter though
memory keyword ==> if you use memory then statevariable will not be updated. as you can see the company name in given below snap shots. btw in latest version of solidity.all variable intialised inside the function set to memory localtion by default.
2. Local variables ==> these var that declared inside the function. these store data in memory which is temporary in nature
3. Global variable ==> these var that store information such blockchain transactions. block number, block timestamp.account address (msg.sender) that call the function.
Constant ==> some time there is a state variable that do not change. so we need to declate regular state variable as constant. constant variable always use less gas fee.
Immutbale ==> some time there is a state variable that do not change like constant variable . so we need to declate regular state variable as immutable. these can bde declared one time in the "constructor".
error handling are moslty done to prevent the uneceesary use of gas. means refund of gas, any variable that is updated will be reverted
require ==> it is mostly used to validate the user inputs and for access control who gets to call the function
revert ==> it is also does same thing as require but it is mostly used to prefer in nested condtions.
mapping is like dictionary in python and object in js. store key value pair. {"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4": 565666}
to delete thevalue from mapping. it will leave the value of key default value that is declared varibale
this is type of memory location where variable is declared and used in inputs. so whenever it is used by another function then that data do not copied in memory. it directly used. so it save gas. """once we declare the variable it can't be modified"""
this is type of memory location where variable is declared and used in inputs. used for temporary value also can be modified
# 3 ways to send ether
these are executed when functions are not existed sends directly ether if fallback function is payable
so if someone call function foo inside this contract but it is not available then fallback function will call by default
these are act as abstraction. these found on top of contract. theae are used to import other contract code. that helps use to avoid the duplication.
lets understand with it example. here in this snapshot there is Counter smart contract. we want to use its Inc() function in other external contract.
if we want to modifie the parent function. then we need to use virtual keyword in parent function and use that same function in child and use override keyword in that function. also visibility of parent and child function should not be differd. check the snap shot of it.
similar to contracts that contain reusable codes. A library has functions that can be called by other contracts.
in this snap shot library is declared outside the function. then in contract library function are accesed using dot notations
It effectively allows smart contracts to act very similarly to a conventional cryptocurrency like Bitcoin, or Ethereum itself. In saying this, a token hosted on the Ethereum blockchain can be sent, received, checked of its total supply, and checked for the amount that is available on an individual address
ERC20 defines the functions balanceOf , totalSupply , transfer , transferFrom , approve , and allowance
transfer() ==> This function lets the owner of the contract send a given amount of the token to another address just like a conventional cryptocurrency transaction
approve function ==> This function lets the owner of the contract approve a given amount of tokens to be spent on behalf of another address.means lets say i am the owner of wallet and i decide whoever want to spend my tokne. i will allow them to spend my token. by giving approval. i will set the limit that the other wallet spend my token.
allowance function ==> This function lets the owner of the contract check the amount of tokens that have been approved for spending on behalf of another address.menas if i am the owner of my wallet and my friend has spend my token on behalf of my wallet. so this function to check how much allowance is remaining for my friend.
transferFrom function ==> This function lets the owner of the contract transfer a given amount of tokens from one address to another address.one address corresponds to the who actual have the token and other address is the one who want to spend the token. transferFrom function is used to spend the token on behalf of the owner of the contract.
ECDSA to the private key, we get a 64-byte integer, which is two 32-byte integers that represent X and Y of the point on the elliptic curve
Address of Account = To make an address from the public key, all we need to do is to apply Keccak-256 to the key and then take the last 20 bytes of the result
contract address = The contract address is usually given when a contract is deployed to the Ethereum Blockchain. The address comes from the creator's address and the number of transactions sent from that address (the “nonce”)
its the first four bytes of a function signature. which gives the idea about which function is called.
call data are function parameter passed to function
it takes two params first is function signature( function name with its params in string) and second is the function parameter. used to call function directly by just mentioning its name in string and passing arguments.
abi.encodeWithSignature("transfer(address,uint256)", someAddress, amount)
it takes two params first is the function signature( function name with its params in the string) and the second is the function parameter. used to call function directly by just mentioning function selector(bytes format of function name) and passing arguments.
abi.encodeWithSelector(getFunctionSelectorOne(), someAddress, amount)
but in this we first need to get the functionSelector