Last active
March 8, 2022 19:37
-
-
Save Turupawn/df17ae2d71c6c64f0773641cb81cb6ce to your computer and use it in GitHub Desktop.
Orcales
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.12; | |
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; | |
/** | |
* Request testnet LINK and ETH here: https://faucets.chain.link/ | |
* Find information on LINK Token Contracts and get the latest ETH and LINK faucets here: https://docs.chain.link/docs/link-token-contracts/ | |
*/ | |
/** | |
* THIS IS AN EXAMPLE CONTRACT WHICH USES HARDCODED VALUES FOR CLARITY. | |
* PLEASE DO NOT USE THIS CODE IN PRODUCTION. | |
*/ | |
contract APIConsumer is ChainlinkClient { | |
using Chainlink for Chainlink.Request; | |
uint256 public volume; | |
address private oracle; | |
bytes32 private jobId; | |
uint256 private fee; | |
/** | |
* Network: Kovan | |
* Oracle: 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8 (Chainlink Devrel | |
* Node) | |
* Job ID: d5270d1c311941d0b08bead21fea7747 | |
* Fee: 0.1 LINK | |
*/ | |
constructor() { | |
setPublicChainlinkToken(); | |
oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8; | |
jobId = "d5270d1c311941d0b08bead21fea7747"; | |
fee = 0.1 * 10 ** 18; // (Varies by network and job) | |
} | |
/** | |
* Create a Chainlink request to retrieve API response, find the target | |
* data, then multiply by 1000000000000000000 (to remove decimal places from data). | |
*/ | |
function requestVolumeData() public returns (bytes32 requestId) | |
{ | |
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); | |
// Set the URL to perform the GET request on | |
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"); | |
// Set the path to find the desired data in the API response, where the response format is: | |
// {"RAW": | |
// {"ETH": | |
// {"USD": | |
// { | |
// "VOLUME24HOUR": xxx.xxx, | |
// } | |
// } | |
// } | |
// } | |
request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); | |
// Multiply the result by 1000000000000000000 to remove decimals | |
int timesAmount = 10**18; | |
request.addInt("times", timesAmount); | |
// Sends the request | |
return sendChainlinkRequestTo(oracle, request, fee); | |
} | |
/** | |
* Receive the response in the form of uint256 | |
*/ | |
function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) | |
{ | |
volume = _volume; | |
} | |
// function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.12; | |
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; | |
contract APIConsumer is ChainlinkClient { | |
using Chainlink for Chainlink.Request; | |
uint256 public volume; | |
address private oracle; | |
bytes32 private jobId; | |
uint256 private fee; | |
constructor() { | |
setPublicChainlinkToken(); | |
oracle = 0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e; | |
jobId = "8c1d083e11db424eacb04a314310599a"; | |
fee = 1 ether; | |
} | |
function requestVolumeData() public returns (bytes32 requestId) | |
{ | |
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); | |
// Set the URL to perform the GET request on | |
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"); | |
// Set the path to find the desired data in the API response, where the response format is: | |
// {"RAW": | |
// {"ETH": | |
// {"USD": | |
// { | |
// "VOLUME24HOUR": xxx.xxx, | |
// } | |
// } | |
// } | |
// } | |
request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); | |
int timesAmount = 10**18; | |
request.addInt("times", timesAmount); | |
return sendChainlinkRequestTo(oracle, request, fee); | |
} | |
function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) | |
{ | |
volume = _volume; | |
} | |
// function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.12; | |
import "@chainlink/contracts/src/v0.8/KeeperCompatible.sol"; | |
contract Counter is KeeperCompatibleInterface { | |
uint public counter; | |
uint public immutable interval; | |
uint public lastTimeStamp; | |
constructor() { | |
interval = 60; // 60 seconds | |
lastTimeStamp = block.timestamp; | |
counter = 0; | |
} | |
function checkUpkeep(bytes calldata checkData) external view override returns (bool upkeepNeeded, bytes memory performData) { | |
checkData; | |
performData; | |
upkeepNeeded = (block.timestamp - lastTimeStamp) > interval; | |
} | |
function performUpkeep(bytes calldata /* performData */) external override { | |
//We highly recommend revalidating the upkeep in the performUpkeep function | |
if ((block.timestamp - lastTimeStamp) > interval ) { | |
lastTimeStamp = block.timestamp; | |
counter = counter + 1; | |
} | |
// We don't use the performData in this example. The performData is generated by the Keeper's call to your checkUpkeep function | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.12; | |
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | |
contract PriceConsumerV3 { | |
AggregatorV3Interface internal priceFeed; | |
address ETH_USD_price = 0x8A753747A1Fa494EC906cE90E9f37563A8AF630e; | |
constructor() { | |
priceFeed = AggregatorV3Interface(ETH_USD_price); | |
} | |
function getLatestPrice() public view returns (int) { | |
( | |
uint80 roundID, | |
int price, | |
uint startedAt, | |
uint timeStamp, | |
uint80 answeredInRound | |
) = priceFeed.latestRoundData(); | |
roundID; | |
startedAt; | |
timeStamp; | |
answeredInRound; | |
return price; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.12; | |
import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol"; | |
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol"; | |
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol"; | |
contract VRFv2Consumer is VRFConsumerBaseV2 { | |
VRFCoordinatorV2Interface COORDINATOR; | |
LinkTokenInterface LINKTOKEN; | |
// Edit here | |
uint64 s_subscriptionId = 949; | |
address vrfCoordinator = 0x6168499c0cFfCaCD319c818142124B7A15E857ab; | |
address link = 0x01BE23585060835E02B77ef475b0Cc51aA1e0709; | |
bytes32 keyHash = 0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc; | |
uint32 callbackGasLimit = 100000; | |
uint16 requestConfirmations = 3; | |
uint32 numWords = 2; | |
uint256[] public s_randomWords; | |
uint256 public s_requestId; | |
address s_owner; | |
constructor() VRFConsumerBaseV2(vrfCoordinator) { | |
COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator); | |
LINKTOKEN = LinkTokenInterface(link); | |
} | |
function requestRandomWords() external { | |
s_requestId = COORDINATOR.requestRandomWords( | |
keyHash, | |
s_subscriptionId, | |
requestConfirmations, | |
callbackGasLimit, | |
numWords | |
); | |
} | |
function fulfillRandomWords( | |
uint256, /* requestId */ | |
uint256[] memory randomWords | |
) internal override { | |
s_randomWords = randomWords; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crea un VRF cosumer:
https://vrf.chain.link/
Consulta los addresses de los precios:
https://docs.chain.link/docs/reference-contracts/
Kovan Faucet
https://faucets.chain.link/
Registra un Keepers:
https://keepers.chain.link/