如何使用链链链球链条接收int数组?
我正在努力从链链API中获取数据,以在我的智能合约中使用它。为此,我正在使用链条甲骨文。
我已经看到工作要获得一个UINT256或一个Bool或一个字节32变量。但是,如果您想收到一个数组怎么办? 我想接收[1、2、3、4]
作为uint []
的内容,以便能够循环并使用单个值。
最好的方法是什么?
我已经使用了get- bytes32和get-> bytes,但是我需要在EVM内解析这些字节,我认为这不是一个好主意。
I'm traing to get data from an off-chain API to use it in my smart contract. For this, I'm using Chainlink oracle.
I've seen jobs to get one Uint256 or one Bool or a Bytes32 variable. But what if you want to receive an array?
I want to receive something like [1, 2, 3, 4]
as an uint[]
to be able to loop and use the individual values.
What's the best way to do this?
I already used the Get->Bytes32 and the Get->Bytes, method but then I need to parse these bytes inside the EVM and I don't think that's a good idea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您当然可以从 Chainlink Oracle 检索数组响应。
如果您想运行自己的 Chainlink 预言机/节点,则需要确保部署了最新的预言机合约(截至本文为止的
Operator.sol
),它支持最广泛的一系列数据类型: https://docs.chain.link/chainlink-nodes/v1/fulfilling-requests#setup-your-operator-contract用于返回 uint256[] 对象的 Chainlink 作业配置应如下所示(仅显示
ethabiencode
作业任务的摘录。请注意,此作业任务的输入${parse}
必然是来自jsonparse
作业任务,应该是一个数组(即[10,20]
)):最后是消费者合约的完成函数(即,在链上接收结果)将如下所示:
如果您只想检索此数据而不运行自己的 Chainlink 预言机,您可以要求现有的节点运营商支持您的请求。
以下链接是如何从现有 Oracle 提供商检索以太坊 Goerli 测试网上的 uint256 数组的示例(免责声明:我是该 Oracle 团队的成员): https://docs.linkwellnodes.io/services/direct-request-jobs/testnets/Ethereum-Goerli-Testnet-Jobs?dataType=Uint256%5B%5D
我希望有所帮助!
You can certainly retrieve an array response from a Chainlink Oracle.
If you'd like to run your own Chainlink oracle / node, you'll need to ensure you have the latest oracle contract deployed (
Operator.sol
as of this post), which supports the broadest array of data types: https://docs.chain.link/chainlink-nodes/v1/fulfilling-requests#setup-your-operator-contractThe Chainlink job configuration for returning a uint256[] object should look something like this (showing an excerpt of the
ethabiencode
job task only. please note that the input${parse}
to this job task is necessarily the output from ajsonparse
job task, which should be an array (ie,[10,20]
)):And finally, the fulfill function of your consumer contract (ie, the function that receives the result on-chain) will look something like this:
If you just want to retrieve this data without running your own Chainlink oracle, you can ask an existing node operator to support your request.
The following link is an example of how to retrieve a uint256 array on Ethereum Goerli testnet from an existing oracle provider (disclaimer: I am a member of this Oracle team): https://docs.linkwellnodes.io/services/direct-request-jobs/testnets/Ethereum-Goerli-Testnet-Jobs?dataType=Uint256%5B%5D
I hope that helps!
目前不支持阵列作为响应类型,此处为当前支持的响应类型的列表。
您可以:
uint256
uint256
值,假设它是一个固定的size数组,bytes32
值。请记住,目前,任何返回值都必须适合32个字节。如果值大于该值,请提出多个请求。At the moment arrays are not supported as a response type, here is the list of currently supported response types.
You can:
uint256
value byuint256
value, assuming it's a fixed-size array, like thisbytes32
values. Keep in mind that, currently, any return value must fit within 32 bytes. If the value is bigger than that, make multiple requests.