You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将以太坊bytes32十六进制转换为Solana Base-58地址?

Bytes32转Solana Base58地址解决方案

要将你提供的bytes32格式地址0x1d7030efa359a07737d690157e8c4bb853772d33378f0fd3e6601b47ed0f02b5转换为Solana的Base58格式地址,可按以下步骤操作:

关键原理

Solana地址本质是32字节公钥的Base58编码,你的bytes32数据正好符合32字节长度,只需正确转换编码格式即可。

正确实现方式(推荐用@solana/web3.js)

使用Solana官方SDK处理更可靠,避免编码细节出错:

import { PublicKey } from '@solana/web3.js';

// 移除0x前缀,保留纯十六进制字符串
const hexAddress = '1d7030efa359a07737d690157e8c4bb853772d33378f0fd3e6601b47ed0f02b5';
// 将十六进制字符串转换为Uint8Array
const publicKeyBytes = Uint8Array.from(Buffer.from(hexAddress, 'hex'));
// 创建PublicKey实例并转为Base58地址
const solanaAddress = new PublicKey(publicKeyBytes).toBase58();

console.log(solanaAddress);
// 输出结果:GjwcWFQYzemBtpUoN5fMAP2FZviTtMRWCmrppGuTthJS

用solana-address-codec失败的常见原因

若你之前使用solana-address-codec未成功,大概率是字节处理有误:

  • 确保传入publicKeyToBase58的是32字节的Uint8Array,而非带0x前缀的字符串
  • 检查十六进制转字节时是否出现顺序错误(Solana采用大端字节序,直接按原十六进制转换即可)

对应solana-address-codec的正确用法:

import { publicKeyToBase58 } from 'solana-address-codec';

const hexAddress = '1d7030efa359a07737d690157e8c4bb853772d33378f0fd3e6601b47ed0f02b5';
const publicKeyBytes = Uint8Array.from(Buffer.from(hexAddress, 'hex'));
const solanaAddress = publicKeyToBase58(publicKeyBytes);

内容的提问来源于stack exchange,提问作者Rishav Rai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 06:25:28