首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >HTTP Chainlink HTTP Get不敲击我的HTTP端点

HTTP Chainlink HTTP Get不敲击我的HTTP端点
EN

Stack Overflow用户
提问于 2022-01-02 16:18:48
回答 1查看 277关注 0票数 2

我正在尝试使用Chainlink使我的Ethereum智能契约连接到外部HTTP端点。继Chainlink的文档(https://docs.chain.link/docs/advanced-tutorial/)之后,我将此合同部署到Rinkeby中。

代码语言:javascript
运行
复制
pragma solidity ^0.8.7;

import "github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/ChainlinkClient.sol";

// MyContract inherits the ChainlinkClient contract to gain the
// functionality of creating Chainlink requests


contract getHTTP is ChainlinkClient {
  using Chainlink for Chainlink.Request;

  bytes32 private thisDoesNotWork;
  address private owner;
  address private ORACLE_ADDRESS = 0x718Cc73722a2621De5F2f0Cb47A5180875f62D60;
  bytes32 private JOBID = stringToBytes32("86b489ec4d84439c96181a8df7b22223");
  string private url = "<myHTTPAddressAsString>"; 

// This endpoint URL is hard coded in my contract, and stored as a string (as in the example code). 
// I control it and can have it reply with whatever I want, which might be an issue, returning data in a format that the oracle rejects

  uint256 constant private ORACLE_PAYMENT = 100000000000000000;

  constructor() public {
    // Set the address for the LINK token for the network
    setPublicChainlinkToken();
    owner = msg.sender;
  }

  function requestBytes() 
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(JOBID, address(this), this.fulfill.selector);
    req.add("get", url);
    sendChainlinkRequestTo(ORACLE_ADDRESS, req, ORACLE_PAYMENT);
  }

  function fulfill(bytes32 _requestId, bytes32 recVal)
    public
    recordChainlinkFulfillment(_requestId)
  {
    thisDoesNotWork = recVal;
  }
  function cancelRequest(
    bytes32 _requestId,
    uint256 _payment,
    bytes4 _callbackFunctionId,
    uint256 _expiration
  )
    public
    onlyOwner
  {
    cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
  }

  
  // withdrawLink allows the owner to withdraw any extra LINK on the contract
  function withdrawLink()
    public
    onlyOwner
  {
    LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
    require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
  }
  
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }
  
   // A helper funciton to make the string a bytes32
  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))
    }
  }
}

我在链接市场(https://market.link/jobs/529c7194-c665-4b30-8d25-5321ea49d9cc)上发现了一个节点,该节点目前在rinkeby上活跃(据Etherscan称,它在过去3天内一直在运行,大概还在工作)。

我部署合同并通过链接为合同提供资金。我通过混合调用requestBytes()函数,一切都按预期进行。Metamask支付天然气,链接从我的合同中删除,我得到一个事务哈希,没有错误。

但是,我的端点从不记录请求尝试,oracle从未在其Etherscan页面上列出事务,我的数据也不存在。

我尝试使用其他工作,从Chainlink市场与类似的结果。

我还尝试使用其他HTTP端点,比如Chainlink示例中的端点,具有类似的结果,但我怀疑这是个问题,因为HTTP请求似乎从未被调用过(因为我的HTTP端点没有记录请求)

如果没有错误消息,并且是Web3开发的新手,我就不知道从哪里开始调试。我在Github:https://github.com/smartcontractkit/documentation/issues/513上找到了这样的评论,并在这里毫无希望地实现了这个建议。

我还发现了这个:Chainlink - Job not being fulfilled,但这也没有帮助。

关于错误可能发生的位置,我目前的考虑是:

  1. ,神谕者被白化,完全拒绝我的请求。已考虑创建自己的节点,但如果可能的话,希望在此阶段避免.

  1. 我在如何格式化合同中的请求时出现了一个类型错误,如我在上面找到和引用的GitHub交换中的示例.

编辑:如果有人有任何建议的话,除了Chainlink之外,我还可以使用其他选项将我的合同连接到HTTP端点。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-08 05:31:43

我最近一直在做一些类似的事情,并建议您尝试使用kovan网络和chainlink拥有的甲骨文。更具体地说,我认为确认您可以使用下面页面上的示例中列出的api、oracle和jobid使其工作是一个好主意.这里:

https://docs.chain.link/docs/advanced-tutorial/#contract-example

一旦您使该示例生效,那么您就可以修改它以供使用。该教程中的工作是返回一个(乘以)uint256.对于你的API来说,我认为这不是你想要的,因为你想要bytes32 --听起来就像.因此,当您尝试将其与返回bytes32的API一起使用时,该作业it为: 7401f318127148a894c00c292e486ffd,如下所示:

https://docs.chain.link/docs/decentralized-oracles-ethereum-mainnet/

另一件事可能是你的问题,是你的api。你说你控制了它的回报..。我认为它可能必须以字节格式返回响应,就像Patrick在他的响应(以及他对他的响应的评论)中所说的那样:

Get a string from any API using Chainlink Large Response Example

希望这会有帮助。如果无法让链接文档中的示例工作,请告诉我。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70557627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档