Solidity

未聲明的標識符 Chainlink.Request memory req = buildChainlinkRequest(specId, address(this), this.fulfill.selector);

  • November 20, 2021

未聲明的標識符

從連結文件複製契約https://docs.chain.link/docs/jobs/types/direct-request/

import "https://github.com/smartcontractkit/chainlink/contracts/src/v0.6/ChainlinkClient.sol";
contract MyClient is ChainlinkClient {
   function doRequest(uint256 _payment) public {
       Chainlink.Request memory req = buildChainlinkRequest(specId, address(this), this.fulfill.selector);
       req.add("fetchURL", "https://datafeed.xyz/eth");
       req.add("jsonPath", "data,result");
       sendChainlinkRequest(req, _payment);
   }

   function fulfill(bytes32 requestID, uint256 answer) public {
       // ...
   }
}

試圖向我的 API/URL https://ljiigsoedk.execute-api.ca-central-1.amazonaws.com/default/wildfire 發出一個簡單的 http get 請求。.

但在不修改任何程式碼的情況下,我得到未聲明的標識符 Chainlink.Request memory req = buildChainlinkRequest(specId, address(this), this.fulfill.selector); 憤怒的混音編譯器指向 >>specID<<

我的節點工作是

type = "directrequest"
schemaVersion = 1
name = "example eth request event spec"
contractAddress = "0xCcbB32b820799DDCadCFeEE472B9804a1397005E"
maxTaskDuration = "0s"
observationSource = """
   ds          [type="http" method=GET url="https://ljiigsoedk.execute-api.ca-central-1.amazonaws.com/default/wildfire"]
   ds_parse    [type="jsonparse" path="FIRE_NUMBE"]
   

   ds -&gt; ds_parse 
"""
externalJobID = "37ab8f92-090e-4d23-9b08-96495f96899f"

還沒有做到那麼遠,我猜我正在遵循正確的步驟來實現這一點..如果沒有,請讓我知道我做錯了什麼..

還是我應該使用這個blob來完成這項工作-.-

// First, we parse the request log and the CBOR payload inside of it
decode_log  [type="ethabidecodelog"
            data="$(jobRun.logData)"
            topics="$(jobRun.logTopics)"
            abi="SomeContractEvent(bytes32 requestID, bytes cborPayload)"]

decode_cbor [type="cborparse"
            data="$(decode_log.cborPayload)"]

// Then, we use the decoded request parameters to make an HTTP fetch
fetch [type="http" method=GET url="$(decode_cbor.fetchURL)"]
parse [type="jsonparse" path="$(decode_cbor.jsonPath)" data="$(fetch)"]

// Finally, we send a response on-chain.
// Note that single-word responses automatically populate
// the requestId.
encode_response [type="ethabiencode"
                abi="(uint256 data)"
                data="{\\"data\\": $(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_mwr)}"
                ]

submit_tx  [type="ethtx" to="0x613a38AC1659769640aaE063C651F48E0250454C" data="$(encode_tx)"]

decode_log -&gt; decode_cbor -&gt; fetch -&gt; parse -&gt; encode_response -&gt; encode_tx -&gt; submit_tx

很可能您的其中一個類型是錯誤的。bytes32例如,您將需要一個specIddoRequest在函式上方的契約程式碼中添加下一行

using Chainlink for Chainlink.Request;

address private oracle;
bytes32 private specId;
uint256 private fee;

constructor() {
  setPublicChainlinkToken();
  oracle = 0xCcbB32b820799DDCadCFeEE472B9804a1397005E; // oracle address from posted job, replace if different
  specId = "37ab8f92090e4d239b0896495f96899f"; // jobId from posted job, replace if different
  fee = 0.1 * 10 ** 18; // your fee goes here, this is default value
}

在buildChainlinkRequest的文件中,第一個參數是bytes32.

文件中有一個範例

bytes32 jobId = "493610cff14346f786f88ed791ab7704";

引用自:https://ethereum.stackexchange.com/questions/113817