英文:
Can a byte array be converted to an Address in Cadence
问题
在Cadence中,从UInt8字节数组构建地址的方法是什么?
文档中有这个例子:
let someAddress: Address = 0x436164656E636521
someAddress.toBytes()
我尝试过的:
let hexStr = String.encodeHex([0,0,0,0,0,0,0,1])
let addrStr = "0x".concat(hexStr) // 得到一个格式为 '0x0000000000000001' 的字符串,但如何转换为地址类型?
能否将UInt8字节数组转换为地址类型?
用例是从一个RLP编码的数据函数参数中构建一个交易中的地址。
英文:
Is there way to construct an Address from a byte array of UInt8 in Cadence?
Docs have this example:
let someAddress: Address = 0x436164656E636521
someAddress.toBytes()
What I've tried:
let hexStr = String.encodeHex([0,0,0,0,0,0,0,1])
let addrStr = "0x".concat(hexStr) // gives a string in format '0x0000000000000001' but how cast to Address type?
Possible to do UInt8 byte array to Address?
The use case is to build an Address in a tx from an RLP-encoded data function argument.
答案1
得分: 0
这份合同提供了一些用于处理地址并从其他类型中解析地址的实用工具。在此处输入字符串的操作可行,例如。
链接:https://github.com/green-goo-dao/flow-utils/blob/main/cadence/contracts/AddressUtils.cdc
英文:
This contract has some utilities for working with Addresses and parsing them from other types. Sending in a string here works for instance.
https://github.com/green-goo-dao/flow-utils/blob/main/cadence/contracts/AddressUtils.cdc
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论