Skip to content

Instantly share code, notes, and snippets.

View alexroan's full-sized avatar

Alex Roan alexroan

View GitHub Profile
@alexroan
alexroan / ExampleOracleClient.sol
Last active September 11, 2021 15:18
ExampleOracleClient.sol
pragma solidity 0.6.0;
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/vendor/Ownable.sol";
contract ExampleOracleClient is ChainlinkClient, Ownable {
address constant private ORACLE = 0x83dA1beEb89Ffaf56d0B7C50aFB0A66Fb4DF8cB1;
string constant private JOB_ID = "93547cb3c6784ec08a366be6211caa24";
uint256 constant private ORACLE_PAYMENT = 1 * LINK / 10;
@alexroan
alexroan / exchange-script.js
Created June 18, 2020 09:51
exchange-script.js
// Contracts
const Exchange = artifacts.require("Exchange")
// Utils
const ether = (n) => {
return new web3.utils.BN(
web3.utils.toWei(n.toString(), 'ether')
)
}
@alexroan
alexroan / truffle-script-log.js
Created June 18, 2020 09:30
truffle-script-log.js
module.exports = async function(callback) {
console.log("IT WORKS");
callback();
}
@alexroan
alexroan / Exchange-outline.sol
Created June 18, 2020 09:23
Exchange-outline.sol
contract Exchange {
//fill an order
function fillOrder(uint256 _id) public {
//...
}
//make order
function makeOrder(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive) public {
//...
@alexroan
alexroan / truffle-script.js
Last active June 18, 2020 09:12
truffle-script-outline.js
module.exports = async function(callback) {
// do some stuff
callback();
}
@alexroan
alexroan / redeemEthFromCompound.js
Created June 5, 2020 09:17
redeemEthFromCompound.js
cEthInstance.methods.redeemUnderlying(redeemAmount).send({from: account})
.once('transactionHash', (hash) => {
// Transaction Hash
})
.on('confirmation', (number, receipt) => {
// Number of confirmations
})
.on('error', (error) => {
console.log(error);
})
@alexroan
alexroan / supplyEthToCompound.js
Created June 5, 2020 09:03
supplyEthToCompound.js
cEthInstance.methods.mint().send({from: account, value: supplyValue})
.once('transactionHash', (hash) => {
// Transaction hash
})
.on('confirmation', (number, receipt) => {
// Number of confirmations
})
.on('error', (error) => {
console.log(error);
});
@alexroan
alexroan / lottery.sol
Created May 27, 2020 11:38
lottery.sol
pragma solidity >=0.6.2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./RandomNumberGenerator.sol";
contract Lottery is Ownable{
@alexroan
alexroan / drawingNumbers.sol
Last active May 27, 2020 11:34
lottery/drawingNumbers.sol
function drawNumber(uint256 _seed) public onlyOwner isState(LotteryState.Open) {
_changeState(LotteryState.Closed);
randomNumberRequestId = RandomNumberGenerator(randomNumberGenerator).request(_seed);
emit NumberRequested(randomNumberRequestId);
}
function numberDrawn(bytes32 _randomNumberRequestId, uint _randomNumber) public onlyRandomGenerator isState(LotteryState.Closed) {
if (_randomNumberRequestId == randomNumberRequestId) {
winningNumber = _randomNumber;
emit NumberDrawn(_randomNumberRequestId, _randomNumber);
@alexroan
alexroan / RandomNumberGenerator.sol
Created May 27, 2020 11:29
lottery/RandomNumberGenerator.sol
pragma solidity ^0.6.2;
import "./VRFConsumerBase.sol";
import "./Lottery.sol";
contract RandomNumberGenerator is VRFConsumerBase {
address requester;
bytes32 keyHash;
uint256 fee;