Skip to content

Instantly share code, notes, and snippets.

View raj-pranav's full-sized avatar
🏠
Blockchain- ETH

Pranav Raj raj-pranav

🏠
Blockchain- ETH
View GitHub Profile
@raj-pranav
raj-pranav / 1_first_contract.sol
Last active January 15, 2022 17:56
Learn solidity from the basics
// SPDX-License-Identifier: MIT-License
pragma solidity ^0.8.0;
contract first_sample {
}
@raj-pranav
raj-pranav / Arithmetic_operators.sol
Created January 25, 2022 19:36
Operators in Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
uint constant T = 10;
contract Arithmetic_Operation {
uint x = 10;
uint y = 20;
@raj-pranav
raj-pranav / Logical_operators.sol
Created January 25, 2022 20:15
Operators in Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
uint constant T = 10;
contract Logical_Operation {
uint x = 10;
uint y = 20;
@raj-pranav
raj-pranav / Comparison_operator.sol
Created January 26, 2022 13:33
Operators in Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract comparison_operator {
uint x = 10;
uint y = 12;
int z = 10;
// Less than
bool res = x < y; // res = true
@raj-pranav
raj-pranav / Bitwise_operators.sol
Created January 26, 2022 18:35
Operators in Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract bitwise_operator {
bytes1 x = 0x16; // bit representation: 00010110
bytes1 y = 0x11; // bit representation: 00010001
// Bitwise 'AND'
bytes1 byte_and = x & y; // 00010110 & 00010001 -> 00010000 -> in byte (0x10)
@raj-pranav
raj-pranav / Function-in-solidity.sol
Created January 29, 2022 20:53
Functions in Solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
// code for view type function
contract sample {
uint s = 10;
function f_name(uint _a) public view returns (uint) {
return _a + block.number;
}
@raj-pranav
raj-pranav / solidity-event.sol
Created January 30, 2022 20:52
Events in Solidity
// SPDX-License-Identifier:MIT
pragma solidity >=0.6.0 <0.9.0;
contract Event_sample {
event HighValueTx(
address _from,
address _to,
uint amount,
uint timeStamp
);
@raj-pranav
raj-pranav / constructor-default.sol
Last active February 1, 2022 19:22
Constructor in solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract Consttr {
constructor () {}
}
@raj-pranav
raj-pranav / if-and-else.sol
Last active February 3, 2022 20:07
control structure - if else
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract demo_if {
uint x = 10;
function Compare (uint _x) external view returns (string memory){
if (_x >= x) { // if section
return 'Given value is greater or equal to x';}
else { // else section
return 'Given value is less than x';
@raj-pranav
raj-pranav / example-for-loop.sol
Last active February 5, 2022 18:18
control-structure-for-loop
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract demo_for {
uint public counter = 0;
function update_cnt() public {
for (uint i=0 ; i<10 ; i++){