Skip to content

Commit

Permalink
added sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
ijonas committed Apr 9, 2023
1 parent 86cf187 commit dbf04cd
Show file tree
Hide file tree
Showing 39 changed files with 1,809 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ethereum-sepolia/Get > Bool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Get > Bool

This job retrieves a `bool` from a internet-facing JSON API.

## Contract Address & JobID

Contract: [0x2362A262148518Ce69600Cc5a6032aC8391233f5](https://sepolia.etherscan.io/address/0x2362A262148518Ce69600Cc5a6032aC8391233f5)
JobID: 7599d3c8f31e4ce78ad2b790cbcfc673

## Parameters

The job requires the following parameters to be specified:

* `get` - internet-facing URL from where the integer is retrieved
* `path` - comma-separated JSON path used to extract the integer value

Note: use commas not dots for JSON paths.

## Price

0 LINK

## Example

If you set the following parameters

* get : https://raw.githubusercontent.com/translucent-link/chainlink-node-jobs/main/ethereum-sepolia/Get%20%3E%20Bool/example.json
* path : values,trueValue

Note: use commas not dots for JSON paths.

You will receive a JSON response that may look like this:

{
"values": {
"trueValue": true,
"falseValue": false
}
}

The job populated with the example parameters above would return with: `true`

See [example.sol](example.sol) for an example client contract.

## Troubleshooting

1. Please make sure you load your client contract, e.g. example.sol, with enough LINK, otherwise you'll get a "Gas estimation failed" error.
2. The contract address and jobId mentioned above are specific to the network and won't work on other networks.
3. Please find us in our [Discord](https://discord.gg/JxKT6R9Xpz) if you're stuck and needing help.
6 changes: 6 additions & 0 deletions ethereum-sepolia/Get > Bool/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": {
"trueValue": true,
"falseValue": false
}
}
61 changes: 61 additions & 0 deletions ethereum-sepolia/Get > Bool/example.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "@chainlink/contracts/src/v0.8/ConfirmedOwner.sol";

/**
* @notice DO NOT USE THIS CODE IN PRODUCTION. This is an example contract.
*/
contract GetBool is ChainlinkClient, ConfirmedOwner {
using Chainlink for Chainlink.Request;

uint256 private constant ORACLE_PAYMENT = 0;
bool public value;

event RequestValue(bytes32 indexed requestId, bool indexed value);

string constant jobId = "a75ebb6e5a7b492fbfb67ab240100a95";

constructor() ConfirmedOwner(msg.sender) {
// ethereum-sepolia
setChainlinkToken(0x779877A7B0D9E8603169DdbD7836e478b4624789);
setChainlinkOracle(0x2362A262148518Ce69600Cc5a6032aC8391233f5);
}

function requestValue(
string memory _url,
string memory _path
) public onlyOwner returns (bytes32 requestId) {
Chainlink.Request memory req = buildChainlinkRequest(
stringToBytes32(jobId),
address(this),
this.fulfillValue.selector
);
req.add("get", _url);
req.add("path", _path);
return sendChainlinkRequest(req, ORACLE_PAYMENT);
}

function fulfillValue(
bytes32 _requestId,
bool _value
) public recordChainlinkFulfillment(_requestId) {
emit RequestValue(_requestId, _value);
value = _value;
}

function stringToBytes32(
string memory source
) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}

assembly {
// solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}
26 changes: 26 additions & 0 deletions ethereum-sepolia/Get > Bool/jobspec.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
type = "directrequest"
schemaVersion = 1
name = "TL Get > Bool"
maxTaskDuration = "0s"
contractAddress = "0x2362A262148518Ce69600Cc5a6032aC8391233f5"
externalJobID = "a75ebb6e-5a7b-492f-bfb6-7ab240100a95"
minIncomingConfirmations = 0
minContractPaymentLinkJuels = 0
observationSource = """
decode_log [type="ethabidecodelog"
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
decode_cbor [type="cborparse" data="$(decode_log.data)"]
fetch [type="http" method=GET url="$(decode_cbor.get)"]
parse [type="jsonparse" path="$(decode_cbor.path)" data="$(fetch)"]
encode_data [type="ethabiencode" abi="(bool value)" data="{ \\"value\\": $(parse) }"]
encode_tx [type="ethabiencode"
abi="fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes32 data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}"
]
submit_tx [type="ethtx" to="0x2362A262148518Ce69600Cc5a6032aC8391233f5" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> encode_data -> encode_tx -> submit_tx
"""
51 changes: 51 additions & 0 deletions ethereum-sepolia/Get > Bytes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Get > Bytes

This job retrieves a variable-length string from an internet-facing JSON API.

## Contract Address & JobID

Contract: [0x2362A262148518Ce69600Cc5a6032aC8391233f5](https://sepolia.etherscan.io/address/0x2362A262148518Ce69600Cc5a6032aC8391233f5)

JobID: a84b561bd8f64300a0832682f208321f

## Parameters

The job requires the following parameters to be specified:

* `get` - internet-facing URL from where the bytes/string is retrieved
* `path` - comma-separated JSON path used to extract the integer value

## Price

0 LINK

## Example

If you set the following parameters

* get : https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD
* path : RAW,ETH,USD,IMAGEURL

Note: use commas not dots for JSON paths.

You will receive a JSON response that may look like this:

{
"RAW": {
"ETH": {
"USD": {
"IMAGEURL": "/media/37746238/eth.png"
}
}
}
}

The job populated with the example parameters above would return with: `/media/37746238/eth.png`

See [example.sol](example.sol) for an example client contract.

## Troubleshooting

1. Please make sure you load your client contract, e.g. example.sol, with enough LINK, otherwise you'll get a "Gas estimation failed" error.
2. The contract address and jobId mentioned above are specific to the network and won't work on other networks.
3. Please find us in our [Discord](https://discord.gg/JxKT6R9Xpz) if you're stuck and needing help.
71 changes: 71 additions & 0 deletions ethereum-sepolia/Get > Bytes/example.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

/**
* @notice DO NOT USE THIS CODE IN PRODUCTION. This is an example contract.
*/
contract GenericLargeResponse is ChainlinkClient {
using Chainlink for Chainlink.Request;

// variable bytes returned in a single oracle response
bytes public data;
string public stringData;
uint256 private constant ORACLE_PAYMENT = 0;

string constant jobId = "a84b561bd8f64300a0832682f208321f";

/**
* @notice Initialize the link token and target oracle
* @dev The oracle address must be an Operator contract for multiword response
*/
constructor() {
// ethereum-sepolia
setChainlinkToken(0x779877A7B0D9E8603169DdbD7836e478b4624789);
setChainlinkOracle(0x2362A262148518Ce69600Cc5a6032aC8391233f5);
}

/**
* @notice Request variable bytes from the oracle
*/
function requestBytes(string memory _url, string memory _path) public {
Chainlink.Request memory req = buildChainlinkRequest(
stringToBytes32(jobId),
address(this),
this.fulfillBytes.selector
);
req.add("get", _url);
req.add("path", _path);
sendOperatorRequest(req, ORACLE_PAYMENT);
}

event RequestFulfilled(bytes32 indexed requestId, bytes indexed data);

/**
* @notice Fulfillment function for variable bytes
* @dev This is called by the oracle. recordChainlinkFulfillment must be used.
*/
function fulfillBytes(
bytes32 requestId,
bytes memory bytesData
) public recordChainlinkFulfillment(requestId) {
emit RequestFulfilled(requestId, bytesData);
data = bytesData;
stringData = string(data);
}

function stringToBytes32(
string memory source
) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}

assembly {
// solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}
30 changes: 30 additions & 0 deletions ethereum-sepolia/Get > Bytes/jobspec.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
type = "directrequest"
schemaVersion = 1
name = "TL Get > Bytes"
externalJobID = "a84b561b-d8f6-4300-a083-2682f208321f"
maxTaskDuration = "0s"
contractAddress = "0x2362A262148518Ce69600Cc5a6032aC8391233f5"
minIncomingConfirmations = 0
minContractPaymentLinkJuels = 0
observationSource = """
decode_log [type="ethabidecodelog"
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
decode_cbor [type="cborparse" data="$(decode_log.data)"]
fetch [type="http" method=GET url="$(decode_cbor.get)" allowUnrestrictedNetworkAccess="true"]
parse [type="jsonparse" path="$(decode_cbor.path)" data="$(fetch)"]
encode_large [type="ethabiencode"
abi="(bytes32 requestId, bytes _data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"_data\\": $(parse)}"
]
encode_tx [type="ethabiencode"
abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_large)}"
]
submit_tx [type="ethtx" to="0x2362A262148518Ce69600Cc5a6032aC8391233f5" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> encode_large -> encode_tx -> submit_tx
"""
61 changes: 61 additions & 0 deletions ethereum-sepolia/Get > Bytes[]/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Get > Bytes[]

This job retrieves a list or array of `bytes` (strings) from a internet-facing JSON API.

## Contract Address & JobID

Contract: [0x2362A262148518Ce69600Cc5a6032aC8391233f5](https://sepolia.etherscan.io/address/0x2362A262148518Ce69600Cc5a6032aC8391233f5)

JobID: b25b7d28184a4f4d8dd33009bbeda4e1

## Parameters

The job requires the following parameters to be specified:

* `get` - internet-facing URL from where the integer is retrieved
* `path` - comma-separated JSON path used to extract the bytes[] values

Note: use commas not dots for JSON paths.

## Price

0 LINK

## Example

If you set the following parameters

* get : https://raw.githubusercontent.com/translucent-link/chainlink-node-jobs/main/ethereum-sepolia/Get%20%3E%20Bytes%5B%5D/example.json
* path : calendar,months

You will receive a JSON response that may look like this:

{
"calendar": {
"months": [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
}
}

The job populated with the example parameters above would return with: `[January, February.... December]`

See [example.sol](example.sol) for an example client contract.

## Troubleshooting

1. You can convert `bytes` to `string` using `const str = string(mybytes);`
2. Please make sure you load your client contract, e.g. example.sol, with enough LINK, otherwise you'll get a "Gas estimation failed" error.
3. The contract address and jobId mentioned above are specific to the network and won't work on other networks.
4. Please find us in our [Discord](https://discord.gg/JxKT6R9Xpz) if you're stuck and needing help.
18 changes: 18 additions & 0 deletions ethereum-sepolia/Get > Bytes[]/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"calendar": {
"months": [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
}
}
Loading

0 comments on commit dbf04cd

Please sign in to comment.