Skip to content

Instantly share code, notes, and snippets.

View alexroan's full-sized avatar

Alex Roan alexroan

View GitHub Profile
@alexroan
alexroan / getWeb3WebSocket.js
Last active May 8, 2020 11:31
getWeb3WebSocket.js
export const getWeb3Socket = (web3) => new Promise( async (resolve, reject) => {
try{
let web3Socket = web3;
const networkName = await web3.eth.net.getNetworkType();
if(networkName === "kovan"){
web3Socket = new Web3(new Web3.providers.WebsocketProvider("wss://kovan.infura.io/ws/v3/xxx"));
}
resolve(web3Socket);
}
catch(error) {
@alexroan
alexroan / MyWallet.sol
Last active May 5, 2020 11:19
MyWallet.sol-v2
pragma solidity ^0.6.0;
import "./contracts/MyToken.sol";
contract MyWallet {
address payable private owner;
address private tokenAddress
constructor(address token) public {
@alexroan
alexroan / MyWallet.sol
Created May 5, 2020 11:12
MyWallet.sol-v1
pragma solidity ^0.6.0;
contract MyWallet {
address payable private owner;
constructor() public {
owner = msg.sender;
}
receive() external payable {
@alexroan
alexroan / MyToken.sol
Last active May 5, 2020 11:17
MyToken.sol-basic-outline
pragma solidity ^0.6.0;
contract MyToken {
mapping (address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
@alexroan
alexroan / TestContract.sol
Created April 29, 2020 08:24
TestContract.sol
pragma solidity ^0.6.0;
import "openzeppelin-solidity/contracts/access/Ownable.sol";
contract TestContract is Ownable {
}
@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");
}
}
@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 / 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 / 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 / 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