NEW

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

GET > Bytes Example Job Spec

This is an example v2 (TOML) job spec for returning bytes in one Chainlink API Call. Note that the job calls the fulfillOracleRequest2 function. If you are a node operator, use an Operator contract with this job. To test it from a smart contract, see this Example.

type = "directrequest"
schemaVersion = 1
name = "Get > Bytes"
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)"]

    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="YOUR_ORACLE_CONTRACT_ADDRESS" data="$(encode_tx)"]

    decode_log -> decode_cbor -> fetch -> parse  -> encode_large -> encode_tx -> submit_tx
"""

This is an example legacy v1 job spec for returning large responses in one Chainlink API Call.

{
  "name": "large-word",
  "initiators": [
    {
      "id": 9,
      "jobSpecId": "7a97ff84-93ec-406d-9062-1b2531f9251a",
      "type": "runlog",
      "params": {
        "address": "0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8"
      }
    }
  ],
  "tasks": [
    {
      "jobSpecId": "7a97ff8493ec406d90621b2531f9251a",
      "type": "httpget"
    },
    {
      "jobSpecId": "7a97ff8493ec406d90621b2531f9251a",
      "type": "jsonparse"
    },
    {
      "jobSpecId": "7a97ff8493ec406d90621b2531f9251a",
      "type": "resultcollect"
    },
    {
      "jobSpecId": "7a97ff8493ec406d90621b2531f9251a",
      "type": "ethtx",
      "confirmations": 1,
      "params": {
        "abiEncoding": ["bytes32", "bytes"]
      }
    }
  ]
}

Stay updated on the latest Chainlink news