Skip to content

Instantly share code, notes, and snippets.

View andrejrakic's full-sized avatar
:octocat:
Building Chainlink

Andrej andrejrakic

:octocat:
Building Chainlink
View GitHub Profile
@andrejrakic
andrejrakic / Mappings.sol
Last active April 28, 2020 08:43
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=
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;
@andrejrakic
andrejrakic / Conditionals&Loops.sol
Created May 7, 2020 10:09
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=
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 / HotelRoom.sol
Created May 7, 2020 11:36
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=
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 / Election.sol
Created May 15, 2020 13:56
Solidity smart contract for Election on Blockchain
pragma solidity >= 0.5.0 < 0.6.0;
// @author Andrej
// @title Election
contract Election {
address payable public contractOwner;
struct Candidate {
string name;
@andrejrakic
andrejrakic / ERC721.sol
Created August 7, 2020 11:37
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
{
/**
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;
// 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

👍 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";
@andrejrakic
andrejrakic / Swapper.sol
Created August 26, 2021 11:28
Simple smart contract to swap two variables in Solidity
// 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 {
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
contract StorageBug is Ownable {
function write(uint256 number) external onlyOwner {
uint256[] storage arr;
arr.push(number);