Skip to content

manh-vv/eosjs-name

Folders and files

NameName
Last commit message
Last commit date
Jan 27, 2023
Jan 27, 2023
Jan 27, 2023
Jan 27, 2023
Oct 26, 2020
Oct 26, 2020
Oct 26, 2020
Jan 27, 2023
Jan 27, 2023
Oct 26, 2020
Jan 27, 2023
Jan 27, 2023
Jan 27, 2023
Jan 27, 2023
Jun 15, 2023

Repository files navigation

Eosio name to uint64

NPM Build Status codecov

Gitpod ready-to-code

npm i eosjs-account-name
yarn add eosjs-account-name
<!-- lib name is: eosjsName -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.js"></script>

Example of browser is in index.html.

From name to uint64

Here is how eosio account name is computed to uint64.

"eosio",
"eosio.msig",
"eosio.token",

---- 6138663577826885632
---- 6138663587900751872
---- 6138663591592764928

From uint64 to name

Source https://github.com/EOSIO/eos/blob/master/libraries/chain/name.cpp#L19

Example

Try on run-kit https://npm.runkit.com/eosjs-account-name

const eosjsAccountName = require('eosjs-account-name');
const n = eosjsAccountName.nameToUint64('eosio');

console.log('eosio to uint64: ' + n);

console.log('uint64 to name: ' + eosjsAccountName.uint64ToName(n));

Parse symbol name

symbol.test.js

const { symbol, nameToUint64 } = require('eosjs-account-name');

/**
 * cleos -u https://eos.greymass.com get scope eosio.token -t stat
 */
const name = '........ehbo5';
const uint64 = nameToUint64(name);
const symbolName = symbol.toName(uint64);

// expect(symbolName).toEqual('EOS');

Note on random eosio name

In case you want to generate a random name, I suggest you use nanoid.

const generate = require('nanoid/generate');
const alphabet = '.12345abcdefghijklmnopqrstuvwxyz';
generate(alphabet, 12); //=> "nc4zs1yyg.jx"