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 / global-variable.sol
Created February 16, 2022 18:55
Variables in Solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract Vars {
// State variables
uint age ;
address public myAddr = msg.sender;
function random() external view returns (uint){
@raj-pranav
raj-pranav / custom-enum-select.sol
Last active February 15, 2022 13:22
Enum in solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract PaymentData {
enum paymodes {
None,
Cash,
Crypto,
Online,
Cheque
@raj-pranav
raj-pranav / add-struct-array-pair.sol
Last active February 14, 2022 17:48
Struct in Solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract struct_sample {
struct myOrg {
string name;
uint num_emp;
}
@raj-pranav
raj-pranav / Dynamic-array.sol
Created February 12, 2022 16:07
Arrays in Solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract array_sample {
uint[] myDynArray ; // length is 0
uint[] someVal = [1,2,3]; // length is 3
// Check the content of each array
function getElements() public view returns (uint[] memory, uint[] memory){
return (myDynArray, someVal);
@raj-pranav
raj-pranav / calldata.sol
Created February 8, 2022 21:11
Storage, Memory and Calldata
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract XYZ {
uint[] x;
function f1 (uint[] calldata _x) external {
x = _x ;
}
@raj-pranav
raj-pranav / mapping-demo.sol
Created February 6, 2022 18:19
Mapping in Solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
contract map_demo {
mapping (address => uint) Eth_users;
function add_amnt(address _myadd, uint _amnt) external {
Eth_users[_myadd] = _amnt;
@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++){
@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 / 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 / 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
);