Solana 文档基础设施即代码标准库

十六进制函数

encode_hex

encode_hex 将缓冲区或字符串编码为带有 0x 前缀的十六进制字符串。

输入

名称类型描述
valuebuffer、string、addon要编码的缓冲区或字符串。以 '0x' 开头的字符串将被解码为十六进制;否则,使用原始 UTF-8 字节。

输出

名称类型描述
valuestring输入内容的十六进制表示形式,带有 0x 前缀
output "encoded_hex" {
value = encode_hex("hello, world")
}
// > encoded_hex: 0x68656c6c6f2c20776f726c64

decode_hex

decode_hex 解码一个十六进制字符串,并将结果以缓冲区形式返回。

输入

名称类型描述
hex_stringstring要解码的十六进制字符串(带或不带 0x 前缀)

输出

名称类型描述
valuebuffer解码后的十六进制字符串,以缓冲区形式返回
output "decoded_hex" {
value = decode_hex("0x68656c6c6f2c20776f726c64")
}
// > decoded_hex: 0x68656c6c6f2c20776f726c64

Is this page helpful?

Table of Contents

Edit Page
©️ 2026 Solana 基金会版权所有