如何从 polkadot public key 获取 Polkadot 地址? Polkadot.js
How to get the Polkadot address from the polkadot public key? Polkadot.js
我试过 @polkadot/util-crypto
lib 和 @polkadot/keyring
转换,public 密钥到 polkadot 地址但没有帮助。
polkadot.js
有什么方法吗?
关于如何获取地址的步骤也很有效。
谢谢
@polkadot/util-crypto
公开函数 encodeAddress
可以输入您的 public 密钥 bytes/hex 并输出 SS58 编码地址。如果你想获取特定网络的地址,比如 Polkadot,你需要提供一个辅助参数,即该网络的 SS58 前缀。在 Polkadot 的情况下它是 0.
https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)#address-type
例如:
let address = util_crypto.encodeAddress("0x263158a10b39debac59bd1239bc64fb4bd678f507814d24f59efd46279111c71", 0)
document.getElementById("output").innerText = address;
<script src="//unpkg.com/polkadot-js-bundle/polkadot.js"></script>
<div id="output"></output>
我试过 @polkadot/util-crypto
lib 和 @polkadot/keyring
转换,public 密钥到 polkadot 地址但没有帮助。
polkadot.js
有什么方法吗?
关于如何获取地址的步骤也很有效。
谢谢
@polkadot/util-crypto
公开函数 encodeAddress
可以输入您的 public 密钥 bytes/hex 并输出 SS58 编码地址。如果你想获取特定网络的地址,比如 Polkadot,你需要提供一个辅助参数,即该网络的 SS58 前缀。在 Polkadot 的情况下它是 0.
https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)#address-type
例如:
let address = util_crypto.encodeAddress("0x263158a10b39debac59bd1239bc64fb4bd678f507814d24f59efd46279111c71", 0)
document.getElementById("output").innerText = address;
<script src="//unpkg.com/polkadot-js-bundle/polkadot.js"></script>
<div id="output"></output>