Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Having fun

Andrej andrejrakic

:octocat:
Having fun
View GitHub Profile
@andrejrakic
andrejrakic / Swapper.sol
Created Aug 26, 2021
Simple smart contract to swap two variables in Solidity
View Swapper.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
// Simple contract to swap two variables in Solidity
contract Swapper {
uint8 public x = 1;
uint8 public y = 2;
function swap() public {
View solidity-order.md

👍 Examples of correct code ordering rule

All units are in order

pragma solidity ^0.7.0;

import "./some/library.sol";
import "./some/other-library.sol";
View reEntracyAttack.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.10;
/*
EtherStore is a contract where you can deposit any amount and withdraw at most
1 Ether per week. This contract is vulnerable to re-entrancy attack.
Let's see why.
1. Deploy EtherStore
2. Deposit 1 Ether each from Account 1 (Alice) and Account 2 (Bob) into EtherStore
View ATestnetConsumer.sol
pragma solidity 0.4.24;
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.4/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.4/vendor/Ownable.sol";
contract ATestnetConsumer is ChainlinkClient, Ownable {
uint256 constant private ORACLE_PAYMENT = 1 * LINK;
uint256 public currentPrice;
int256 public changeDay;
View ERC721.sol
pragma solidity ^0.5.1;
/**
* @dev ERC-721 non-fungible token standard.
* See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md.
*/
interface ERC721
{
/**
@andrejrakic
andrejrakic / Election.sol
Created May 15, 2020
Solidity smart contract for Election on Blockchain
View Election.sol
pragma solidity >= 0.5.0 < 0.6.0;
// @author Andrej
// @title Election
contract Election {
address payable public contractOwner;
struct Candidate {
string name;
@andrejrakic
andrejrakic / HotelRoom.sol
Created May 7, 2020
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.6+commit.6c089d02.js&optimize=false&gist=
View HotelRoom.sol
pragma solidity ^0.6.0;
contract HotelRoom {
enum Statuses { Vacant, Occupied }
Statuses currentStatus;
event Occupy(address _occupant, uint _amount);
address payable public owner;
@andrejrakic
andrejrakic / Conditionals&Loops.sol
Created May 7, 2020
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.6+commit.6c089d02.js&optimize=false&gist=
View Conditionals&Loops.sol
pragma solidity ^0.6.0;
contract MyContract {
uint[] public numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
address public owner;
constructor() public {
owner = msg.sender;
@andrejrakic
andrejrakic / Mappings.sol
Last active Apr 28, 2020
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.6+commit.6c089d02.js&optimize=false&gist=
View Mappings.sol
pragma solidity ^0.6.0;
contract Mappings {
// Mappings are data structure like dictionary in C# or hash tables in C++
// O(1)
// mapping(key => value) myMapping;
// One can make nested mappings as well
// Mappings are like databases for blockchain and they are very useful
mapping(uint => string) public names;