首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >链接: Oracle在Avalanche Testnet Fuji上获取外部API数据

链接: Oracle在Avalanche Testnet Fuji上获取外部API数据
EN

Stack Overflow用户
提问于 2022-01-10 12:23:52
回答 1查看 283关注 0票数 0

我正在构建一个与chainlink oracle交互以从api调用获取外部数据的智能契约。我在上这样做,它可以使用下面的oracle地址&作业it,但是它不适用于Avalanche

  • 网络: Kovan
  • 职务名称: Get > Uint256
  • Oracle: 0xc57B33452b4F7B189bB5AfaE9cc4aBa1f7a4FD8 (Chainlink Devrel Node)
  • 职务ID: d5270d1c311941d0b08bead21fea7747
  • 费用: 0.1链接

  • 网络:雪崩测试网
  • 职务名称: Get > Uint256
  • Oracle: 0xCC80934EAf22b2C8dBf7A69e8E0D356a7CAc5754 (Chainlink Devrel Node)
  • 工作ID: 5ca4fa9b2d64462290abfbda84e38cf4
  • 费用: 0.1链接

在下面,您可以找到我使用Remix部署在上的稳固代码&。(在构造函数中,您可以找到脚本的注释。)

以下是已部署的两份合同:

伊瑟姆·科万:https://kovan.etherscan.io/address/0xD20dd5ee7844E27Fa2DD437744f986C121aDDE0f

雪崩富士:https://testnet.snowtrace.io/address/0xfb0368e7a97b2ea12980c3900e9c52806e68e8a6

我注意到,在"events“选项卡上,Kovan上有两个事件:

chainlinkRequested & chainlinkFulfilled

关于富士,我只有一件事.

只有chainlinkRequested,所以看起来甲骨文没有返回数据来发出事件: chainlinkFulfilled .

请你帮我看一下,把api数据拿回来给智能合同好吗?否则,你有什么文档可以帮助我建立我自己的先知吗?(我已经有了cryptozombies.io文档,所以如果有,请与其他文档共享。)

代码语言:javascript
复制
    // SPDX-License-Identifier: MIT

普拉格玛坚实度^0.8.7;

代码语言:javascript
复制
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

/**
 * Request testnet LINK and ETH here: https://faucets.chain.link/
 * Find information on LINK Token Contracts and get the latest ETH and LINK faucets here: https://docs.chain.link/docs/link-token-contracts/
 */

/**
 * THIS IS AN EXAMPLE CONTRACT WHICH USES HARDCODED VALUES FOR CLARITY.
 * PLEASE DO NOT USE THIS CODE IN PRODUCTION.
 */
contract APIPlayerScore is ChainlinkClient {
    using Chainlink for Chainlink.Request;
  
    uint256 public playerScore;
    
    address private oracle;
    bytes32 private jobId;
    uint256 private fee;
    
    constructor() {
        //Ethereum Kovan
        setPublicChainlinkToken();
        oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8;
        jobId = "d5270d1c311941d0b08bead21fea7747";
        fee = 0.1 * 10 ** 18; // (Varies by network and job)

        //Avalanche Fuji
        //setChainlinkToken(0x0b9d5D9136855f6FEc3c0993feE6E9CE8a297846);
        //oracle = 0xCC80934EAf22b2C8dBf7A69e8E0D356a7CAc5754;
        //jobId = "5ca4fa9b2d64462290abfbda84e38cf4";
        //fee = 0.1 * 10 ** 18;
    }
    
    /**
     * Create a Chainlink request to retrieve API response, find the target
     * data, then multiply by 1000000000000000000 (to remove decimal places from data).
     */
    function requestPlayerScoreData() public returns (bytes32 requestId) 
    {
        Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
        
        // Set the URL to perform the GET request on
        request.add("get", "https://****database.app/data.json");
        
        // Set the path to find the desired data in the API response, where the response format is:
        // {"player": {
        //            "id": "4291820",
        //            "score": 560
        //        }
        //  }
        request.add("path", "player.score");
        
        
        // Sends the request
        return sendChainlinkRequestTo(oracle, request, fee);
    }
    
    /**
     * Receive the response in the form of uint256
     */ 
    function fulfill(bytes32 _requestId, uint256 _score) public recordChainlinkFulfillment(_requestId)
    {
        playerScore = _score;
    }

    // function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-22 23:02:38

我成功地通过使用Frensprotocol oracle实现了来自智能契约的外部API调用。文档帮了忙。要使Oracle正常工作,您可以在不和谐或Twitter上与他们的团队联系。

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

https://stackoverflow.com/questions/70652339

复制
相关文章

相似问题

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