NEW

Developer Passes are now available for Chainlink SmartCon. Get yours today.

Existing Job Example specs

This is an example v2 (TOML) job spec for returning gas price using etherscan in one Chainlink API Call. Note that the job :

To test this job spec from a smart contract, see this Example.

type = "directrequest"
schemaVersion = 1
name = "Etherscan gas price"
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_CONTRACT_ADDRESS"
minIncomingConfirmations = 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)"]

    etherscanFast  [type="bridge" name="etherscan" requestData="{\\"data\\": {\\"endpoint\\": \\"gasprice\\",  \\"speed\\":\\"fast\\" }}"]
    etherscanAverage  [type="bridge" name="etherscan" requestData="{\\"data\\": {\\"endpoint\\": \\"gasprice\\",  \\"speed\\":\\"medium\\" }}"]
    etherscanSafe  [type="bridge" name="etherscan" requestData="{\\"data\\": {\\"endpoint\\": \\"gasprice\\",  \\"speed\\":\\"safe\\" }}"]

    decode_log -> etherscanFast
    decode_log -> etherscanAverage
    decode_log -> etherscanSafe

    gasPriceFast    [type=jsonparse path="data,result"]
    gasPriceAverage    [type=jsonparse path="data,result"]
    gasPriceSafe    [type=jsonparse path="data,result"]

    etherscanFast -> gasPriceFast
    etherscanAverage -> gasPriceAverage
    etherscanSafe -> gasPriceSafe

    gasPriceFast -> encode_data
    gasPriceAverage -> encode_data
    gasPriceSafe -> encode_data

    encode_data [type=ethabiencode abi="(bytes32 _requestId, uint256 _fastPrice, uint256 _averagePrice, uint256 _safePrice)"
            data="{\\"_requestId\\": $(decode_log.requestId),\\"_fastPrice\\": $(gasPriceFast),\\"_averagePrice\\": $(gasPriceAverage),\\"_safePrice\\": $(gasPriceSafe)}"]

    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_data)}"]

    submit_tx [type=ethtx to="YOUR_ORACLE_CONTRACT_ADDRESS" data="$(encode_tx)"]
    encode_data -> encode_tx -> submit_tx
"""

Stay updated on the latest Chainlink news