@polkadot/util-crypto#setSS58Format TypeScript Examples
The following examples show how to use
@polkadot/util-crypto#setSS58Format.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Api.tsx From crust-apps with Apache License 2.0 | 5 votes |
async function loadOnReady (api: ApiPromise, injectedPromise: Promise<InjectedExtension[]>, store: KeyringStore | undefined, types: Record<string, Record<string, string>>): Promise<ApiState> {
registry.register(types);
const { injectedAccounts, properties, systemChain, systemChainType, systemName, systemVersion } = await retrieve(api, injectedPromise);
const ss58Format = settings.prefix === -1
? properties.ss58Format.unwrapOr(DEFAULT_SS58).toNumber()
: settings.prefix;
const tokenSymbol = properties.tokenSymbol.unwrapOr([formatBalance.getDefaults().unit, ...DEFAULT_AUX]);
const tokenDecimals = properties.tokenDecimals.unwrapOr([DEFAULT_DECIMALS]);
const isEthereum = ethereumChains.includes(api.runtimeVersion.specName.toString());
const isDevelopment = (systemChainType.isDevelopment || systemChainType.isLocal || isTestChain(systemChain));
console.log(`chain: ${systemChain} (${systemChainType.toString()}), ${JSON.stringify(properties)}`);
// explicitly override the ss58Format as specified
registry.setChainProperties(registry.createType('ChainProperties', { ss58Format, tokenDecimals, tokenSymbol }));
// FIXME This should be removed (however we have some hanging bits, e.g. vanity)
setSS58Format(ss58Format);
// first setup the UI helpers
formatBalance.setDefaults({
decimals: (tokenDecimals as BN[]).map((b) => b.toNumber()),
unit: tokenSymbol[0].toString()
});
TokenUnit.setAbbr(tokenSymbol[0].toString());
// finally load the keyring
isKeyringLoaded() || keyring.loadAll({
genesisHash: api.genesisHash,
isDevelopment,
ss58Format,
store,
type: isEthereum ? 'ethereum' : 'ed25519'
}, injectedAccounts);
const defaultSection = Object.keys(api.tx)[0];
const defaultMethod = Object.keys(api.tx[defaultSection])[0];
const apiDefaultTx = api.tx[defaultSection][defaultMethod];
const apiDefaultTxSudo = (api.tx.system && api.tx.system.setCode) || apiDefaultTx;
setDeriveCache(api.genesisHash.toHex(), deriveMapCache);
return {
apiDefaultTx,
apiDefaultTxSudo,
hasInjectedAccounts: injectedAccounts.length !== 0,
isApiReady: true,
isDevelopment: isEthereum ? false : isDevelopment,
isEthereum,
systemChain,
systemName,
systemVersion
};
}