我正在构建一个与chainlink oracle交互以从api调用获取外部数据的智能契约。我在上这样做,它可以使用下面的oracle地址&作业it,但是它不适用于Avalanche
和
在下面,您可以找到我使用Remix部署在上的稳固代码&。(在构造函数中,您可以找到脚本的注释。)
以下是已部署的两份合同:
伊瑟姆·科万:https://kovan.etherscan.io/address/0xD20dd5ee7844E27Fa2DD437744f986C121aDDE0f
雪崩富士:https://testnet.snowtrace.io/address/0xfb0368e7a97b2ea12980c3900e9c52806e68e8a6
我注意到,在"events“选项卡上,Kovan上有两个事件:
chainlinkRequested & chainlinkFulfilled

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

请你帮我看一下,把api数据拿回来给智能合同好吗?否则,你有什么文档可以帮助我建立我自己的先知吗?(我已经有了cryptozombies.io文档,所以如果有,请与其他文档共享。)
// SPDX-License-Identifier: MIT普拉格玛坚实度^0.8.7;
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
}发布于 2022-07-22 23:02:38
我成功地通过使用Frensprotocol oracle实现了来自智能契约的外部API调用。文档帮了忙。要使Oracle正常工作,您可以在不和谐或Twitter上与他们的团队联系。
https://stackoverflow.com/questions/70652339
复制相似问题