正如标题说的那样,我有一份可靠的、聪明的合同,我正试图从Uniswap合同中导入一些公开的数据。特别是,我希望将tx数据存储在我的合同中(比如说最近的10 tx)。
我不想使用web3.js接口来实现这一点,但我希望在我的合同中实现这一点。
我正在考虑以某种方式使用Oraclize (我从未使用过这个)。是否有可能查询已部署的智能契约并通过tx数据?最好的办法是什么?
发布于 2020-11-23 13:25:23
听起来,您希望通过API获取外部数据。要做到这一点,您必须使用甲骨文。
在不使用web3.js或其他方式与链交互的情况下,您将需要与确实与链、API或其他方面交互的服务进行交互。以太扫描有一个API很可能提供你想要的东西。
一旦你把这两个部分组合在一起,即:
这将是如何以集中的方式提取数据。请使用多个数据源和多个链接预言来获得生产实例的分散聚合答案。
您可以创建一个链式API调用,然后获取数据。一份完整的合同如下所示。只需将API和路径交换给您所寻找的内容即可。您也可以在链式文档中找到混合示例。
pragma solidity ^0.6.0;
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
uint256 public volume;
address private oracle;
bytes32 private jobId;
uint256 private fee;
/**
* Network: Kovan
* Oracle: Chainlink - 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
* Job ID: Chainlink - 29fa9aa13bf1468788b7cc4a500a45b8
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
jobId = "29fa9aa13bf1468788b7cc4a500a45b8";
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
/**
* Create a Chainlink request to retrieve API response, find the target
* data, then multiply by 1000000000000000000 (to remove decimal places from data).
*/
function requestVolumeData() 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://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
// Set the path to find the desired data in the API response, where the response format is:
// {"RAW":
// {"ETH":
// {"USD":
// {
// "VOLUME24HOUR": xxx.xxx,
// }
// }
// }
// }
request.add("path", "RAW.ETH.USD.VOLUME24HOUR");
// Multiply the result by 1000000000000000000 to remove decimals
int timesAmount = 10**18;
request.addInt("times", timesAmount);
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId)
{
volume = _volume;
}
}注:我是链式DevRel
https://ethereum.stackexchange.com/questions/90437
复制相似问题