@polkadot/util#numberToU8a TypeScript Examples
The following examples show how to use
@polkadot/util#numberToU8a.
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: address.ts From subscan-multisig-react with Apache License 2.0 | 6 votes |
export function dvmAddressToAccountId(address: string | null | undefined): AccountId {
if (!address) {
return registry.createType('AccountId', '');
}
// eslint-disable-next-line no-magic-numbers
const data = new Uint8Array(32);
data.set(stringToU8a('dvm:'));
// eslint-disable-next-line no-magic-numbers
data.set(hexToU8a(address), 11);
// eslint-disable-next-line no-bitwise
const checksum = data.reduce((pre: number, current: number): number => pre ^ current);
// eslint-disable-next-line no-magic-numbers
data.set(numberToU8a(checksum), 31);
const accountId = registry.createType<AccountId>('AccountId', data);
return accountId;
}