如何从帐户 ID 获取 SS58 地址?
How can I get SS58 address from Account ID?
如何从帐户 ID 中获取 SS58 地址?
帐户 ID:0x6d6f646c63622f62726964670000000000000000000000000000000000000000
ss58 地址:?
https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)
你可以使用 JS 库来简单地做到这一点:https://substrate.dev/docs/en/knowledgebase/advanced/ss58-address-format#polkadotjs
这是一组使用该库的工具:https://www.shawntabrizi.com/substrate-js-utilities/
// Import Polkadot.js API dependencies.
const { decodeAddress, encodeAddress } = require("@polkadot/keyring");
const { hexToU8a, isHex } = require("@polkadot/util");
// Specify an address to test.
const address = "<addressToTest>";
// Check address.
const isValidSubstrateAddress = () => {
try {
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
return true;
} catch (error) {
return false;
}
};
// Query result.
const isValid = isValidSubstrateAddress();
console.log(isValid);
另外,您可以使用SS58在线地址转换器:https://ss58.org
例如,当使用 Substrate 网络前缀 (42) 时,您的帐户 ID 将产生以下地址:
5EYCAe5g7bGpFHagwe26HiRHdHdE3hobrwV6hq1UD2BPAiZb
如何从帐户 ID 中获取 SS58 地址? 帐户 ID:0x6d6f646c63622f62726964670000000000000000000000000000000000000000 ss58 地址:?
https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)
你可以使用 JS 库来简单地做到这一点:https://substrate.dev/docs/en/knowledgebase/advanced/ss58-address-format#polkadotjs
这是一组使用该库的工具:https://www.shawntabrizi.com/substrate-js-utilities/
// Import Polkadot.js API dependencies.
const { decodeAddress, encodeAddress } = require("@polkadot/keyring");
const { hexToU8a, isHex } = require("@polkadot/util");
// Specify an address to test.
const address = "<addressToTest>";
// Check address.
const isValidSubstrateAddress = () => {
try {
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
return true;
} catch (error) {
return false;
}
};
// Query result.
const isValid = isValidSubstrateAddress();
console.log(isValid);
另外,您可以使用SS58在线地址转换器:https://ss58.org
例如,当使用 Substrate 网络前缀 (42) 时,您的帐户 ID 将产生以下地址:
5EYCAe5g7bGpFHagwe26HiRHdHdE3hobrwV6hq1UD2BPAiZb