无法将智能合约部署到 Polygon、Gas 估算错误、内部 JSON-RPC 错误

发布于 2025-01-10 02:19:31 字数 3592 浏览 5 评论 0原文

下午好,

我是 Polygon 的新手(但有一些以太坊经验),我正在尝试从 chainlink 文档部署智能合约 https://docs.chain.link/docs/fulfilling-requests/ 在 Polygon MUMBAI 测试网上,使用 remix 作为我的浏览器 IDE。

我最初尝试启动文档中发布的原始合约。我收到此错误消息:

“气体估计错误,并显示以下消息(见下文)。交易执行可能会失败。是否要强制发送? 内部 JSON-RPC 错误。 { "code": -32000, "message": "execution reverted" }"

当失败时,我将其修剪为更小、更简单的合约(以防 Polygon 上有智能合约大小限制) )。这是精简后的代码:

// 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";

contract ATestnetConsumer is ChainlinkClient, ConfirmedOwner {
  using Chainlink for Chainlink.Request;

  uint256 constant private ORACLE_PAYMENT = 1 * LINK_DIVISIBILITY/10;
  uint256 public currentPrice;
  int256 public changeDay;
  bytes32 public lastMarket;

  event RequestEthereumPriceFulfilled(
    bytes32 indexed requestId,
    uint256 indexed price
  );

  constructor() ConfirmedOwner(msg.sender){
    setPublicChainlinkToken();
  }

  function requestEthereumPrice(address _oracle, string memory _jobId)
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), address(this), this.fulfillEthereumPrice.selector);
    req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD");
    req.add("path", "USD");
    req.addInt("times", 100);
    sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
  }

  function fulfillEthereumPrice(bytes32 _requestId, uint256 _price)
    public
    recordChainlinkFulfillment(_requestId)
  {
    emit RequestEthereumPriceFulfilled(_requestId, _price);
    currentPrice = _price;
  }

  function getChainlinkToken() public view returns (address) {
    return chainlinkTokenAddress();
  }

  function withdrawLink() public onlyOwner {
    LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
    require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
  }

  function cancelRequest(
    bytes32 _requestId,
    uint256 _payment,
    bytes4 _callbackFunctionId,
    uint256 _expiration
  )
    public
    onlyOwner
  {
    cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
  }

  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))
    }
  }
}

但我遇到了同样的错误。我的钱包由 Polygon(孟买)上的 MATIC 和 LINK 提供资金,我可以将预言机合约部署到孟买测试网(并且)。可以在多边形扫描上看到它 https://mumbai.polygonscan.com/address/0x078cF10C20f7A8aac7b49F078B38007A49334b96),所以看起来一切都设置正确,只是由于某种原因这个合同出错了。

我还增加了我愿意的最大气体付款,我试图推动交易通过(它进行挖掘,但生成的合同没有任何数据https://mumbai.polygonscan.com/address/0xb9bc5681a15353c9b1b19d3db097323b92137ddd)。

我还能够部署一个不使用 Oracle 的合约,但它是孟买的工作合约(在 Rinkeby 上),进一步表明其特定于该合约,或者总体上 Polygon 上的 Chainlink 基础设施。

旁注,我正在尝试在 Polygon 上运行和使用我自己的 Chainlink 节点,但这不会影响此问题,因为在这个演示合约中,当您调用此函数时,您将节点信息和作业 ID 作为参数发送,它不在智能合约本身中。

我的想法是错误的: -合同尺寸太大(即使我把它缩小了??) -MATIC 不是多边形上天然气的唯一货币? - 普汇中金文档存在未知错误 - Polygon 的独特之处在于抛出错误,

谢谢!

Good afternoon,

I am new to Polygon (but have some Ethereum experience) and I am attempting to deploy the smart contract from the chainlink documentation https://docs.chain.link/docs/fulfilling-requests/ on the Polygon MUMBAI testnet, using remix as my in browser IDE.

I initially attempted to launch the original contract, as published in the docs. I got this error message:

"Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" }"

When that failed, I trimmed it down to a smaller, more bare bones contract (in case there is a smart contract size limit on Polygon). Here is the trimmed down code:

// 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";

contract ATestnetConsumer is ChainlinkClient, ConfirmedOwner {
  using Chainlink for Chainlink.Request;

  uint256 constant private ORACLE_PAYMENT = 1 * LINK_DIVISIBILITY/10;
  uint256 public currentPrice;
  int256 public changeDay;
  bytes32 public lastMarket;

  event RequestEthereumPriceFulfilled(
    bytes32 indexed requestId,
    uint256 indexed price
  );

  constructor() ConfirmedOwner(msg.sender){
    setPublicChainlinkToken();
  }

  function requestEthereumPrice(address _oracle, string memory _jobId)
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), address(this), this.fulfillEthereumPrice.selector);
    req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD");
    req.add("path", "USD");
    req.addInt("times", 100);
    sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
  }

  function fulfillEthereumPrice(bytes32 _requestId, uint256 _price)
    public
    recordChainlinkFulfillment(_requestId)
  {
    emit RequestEthereumPriceFulfilled(_requestId, _price);
    currentPrice = _price;
  }

  function getChainlinkToken() public view returns (address) {
    return chainlinkTokenAddress();
  }

  function withdrawLink() public onlyOwner {
    LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
    require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
  }

  function cancelRequest(
    bytes32 _requestId,
    uint256 _payment,
    bytes4 _callbackFunctionId,
    uint256 _expiration
  )
    public
    onlyOwner
  {
    cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
  }

  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))
    }
  }
}

But I get the same error. My wallet is funded with MATIC and LINK on polygon (mumbai). I am able to deploy the oracle contract to the mumbai testnet (and can see it on polygon scan https://mumbai.polygonscan.com/address/0x078cF10C20f7A8aac7b49F078B38007A49334b96 ), so it appears its all set up correctly, just for some reason this contract errors out.

I also increased the max gas I was willing to pay, I have attempted to just push the transaction through (it mines but the resulting contract fails to have any data https://mumbai.polygonscan.com/address/0xb9bc5681a15353c9b1b19d3db097323b92137ddd ).

I was also able to deploy a contract that does does not use Oracles but is a working contract (on Rinkeby) to Mumbai, further indicating its specific to this contract, or the Chainlink infrastructure on Polygon in general.

Side note, I am attempting to run and use my own Chainlink node on Polygon, but that should not be effecting this issue, as in this demo contract you send the node info and the job ID as parameters when you make a call to this function, its not in the smart contract itself.

What I have considered is wrong:
-Contract size is too big (even after I trimmed it down??)
-MATIC is not the only currency for gas on polygon?
-There is an unknown error in the Chinlink Documentation
-Something unique about Polygon is throwing an error

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖正好 2025-01-17 02:19:31

在逐行检查和注释之后,我能够找到有问题的代码。我进去并将 ChainlinkClient.sol 中的 LINK 地址更改为孟买 LINK 地址。如所写,演示代码调用 setPublicChainlinkToken();然后将存储的值分配为链接令牌地址。将该值更改为正确的地址并没有解决我的问题。相反,我使用 setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);这已经解决了我的问题。

After going through and commenting line by line, I was able to track down the code that was at fault. I had gone in and changed the LINK address in ChainlinkClient.sol to the mumbai LINK address. As written, the demo code calls setPublicChainlinkToken(); which then assigns the stored value as the link token address. Changing that value to the correct address did not solve my issue. Instead, I used setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB); and that has cleared up my issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文