Skip to content

Instantly share code, notes, and snippets.

View alexroan's full-sized avatar

Alex Roan alexroan

View GitHub Profile
@alexroan
alexroan / MediumRSS.js
Last active April 12, 2020 11:00
MediumRSS.js
let parser = new RSSParser();
parser.parseURL('https://medium.com/feed/@alexroan/', function(err, feed) {
if (err) throw err;
for (let i = 0; i < 3; i++) {
const entry = feed.items[i];
printPost(entry);
}
});
function printPost(entry) {
@alexroan
alexroan / Ownable.sol
Created April 15, 2020 11:11
Ownable.sol
pragma solidity ^0.5.0;
import "../GSN/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
@alexroan
alexroan / BasicRoles.sol
Created April 22, 2020 09:14
BasicRoles.sol
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/access/Roles.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
contract MyToken is ERC20, ERC20Detailed {
using Roles for Roles.Role;
Roles.Role private _minters;
@alexroan
alexroan / Roles.sol
Created April 22, 2020 09:15
Roles.sol
pragma solidity ^0.5.0;
/**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/
library Roles {
struct Role {
mapping (address => bool) bearer;
}
@alexroan
alexroan / SafeMath.sol
Created April 22, 2020 09:22
SafeMath.sol
pragma solidity ^0.5.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
@alexroan
alexroan / SafeCast.sol
Created April 22, 2020 09:26
SafeCast.sol
pragma solidity ^0.5.0;
/**
* @dev Wrappers over Solidity's uintXX casting operators with added overflow
* checks.
*
* Downcasting from uint256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
@alexroan
alexroan / BasicERC20Detailed.sol
Created April 22, 2020 09:31
BasicERC20Detailed.sol
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
contract GLDToken is ERC20, ERC20Detailed {
constructor(uint256 initialSupply) ERC20Detailed("Gold", "GLD", 18) public {
_mint(msg.sender, initialSupply);
}
}
@alexroan
alexroan / BasicERC721Full.sol
Created April 22, 2020 09:33
BasicERC721Full.sol
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC721/ERC721Full.sol";
import "@openzeppelin/contracts/drafts/Counters.sol";
contract GameItem is ERC721Full {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721Full("GameItem", "ITM") public {
@alexroan
alexroan / BasicAddressUtils.sol
Created April 22, 2020 09:37
BasicAddressUtils.sol
pragma solidity ^0.5.5;
import "@openzeppelin/contracts/utils/Address.sol";
contract BasicUtils {
using Address for address;
function checkIfContract(address _addr) public {
return _addr.isContract();
}
@alexroan
alexroan / BeforeTransferHook.sol
Created April 22, 2020 13:07
BeforeTransferHook.sol
// Tokens can only be transferred, minted or burned if the contract is not paused
contract ERC20Pausable is ERC20, Pausable {
function _beforeTokenTransfer(address from, address to, uint256 amount)
internal virtual override
{
super._beforeTokenTransfer(from, to, amount);
require(!paused(), "ERC20Pausable: token transfer while paused");
}
}