是否可以通过直接请求 V2 工作规范返回地址?

发布于 2025-01-15 00:29:54 字数 422 浏览 2 评论 0原文

是否可以使用 Chainlink Direct Request V2 作业规范返回地址

我注意到 ETH 地址 大约为 42 字节,因此它不适合 bytes32 响应类型。我看到列出的“响应类型 " 在文档列表中:

  • uint256
  • int256
  • bool
  • bytes32 / bytes

Is it possible to return an address with Chainlink Direct Request V2 Job Specs?

I've noticed an ETH address is around 42 bytes so it won't fit into a bytes32 response type. I see the listed "Response Types" in the docs list:

  • uint256
  • int256
  • bool
  • bytes32 / bytes

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

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

发布评论

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

评论(1

白云不回头 2025-01-22 00:29:54

您想要返回一个bytes32,然后将其转换为地址。

来自 solidity 文档

如果将使用较大字节大小的类型转换为地址(例如 bytes32),则该地址将被截断。为了减少转换歧义,0.4.24 版及更高版本的编译器强制您在转换中显式进行截断。以 32 字节值 0x111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFFCCCC 为例。

您可以使用address(uint160(bytes20(b))),其结果为0x111122223333444455556666777788889999aAaa,或者您可以使用address(uint160(uint256(b) ))),结果是0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc

另请参阅此相关问题。

You'd want to return a bytes32 and then convert it to an address.

From the solidity docs:

If you convert a type that uses a larger byte size to an address, for example bytes32, then the address is truncated. To reduce conversion ambiguity version 0.4.24 and higher of the compiler force you make the truncation explicit in the conversion. Take for example the 32-byte value 0x111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFFCCCC.

You can use address(uint160(bytes20(b))), which results in 0x111122223333444455556666777788889999aAaa, or you can use address(uint160(uint256(b))), which results in 0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc.

Also see this related question.

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