Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manh-vv/eosjs-name
eos name in string to uint64 and vice versa
https://github.com/manh-vv/eosjs-name
eosio name symbol
Last synced: about 1 month ago
JSON representation
eos name in string to uint64 and vice versa
- Host: GitHub
- URL: https://github.com/manh-vv/eosjs-name
- Owner: manh-vv
- Created: 2019-09-29T15:50:13.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-19T00:09:17.000Z (over 1 year ago)
- Last Synced: 2024-04-13T14:40:39.253Z (8 months ago)
- Topics: eosio, name, symbol
- Language: JavaScript
- Homepage: https://manh-vv.github.io/eosjs-name
- Size: 1.33 MB
- Stars: 10
- Watchers: 1
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-eosio - manh-vv/eosjs-name - Convert an Eosio name to uint64 and back. (Developers / Developer Tools)
README
# Eosio name to uint64
[![NPM](https://img.shields.io/npm/v/eosjs-account-name.svg)](https://www.npmjs.org/package/eosjs-account-name)
[![Build Status](https://travis-ci.org/manh-vv/eosjs-name.svg?branch=master)](https://travis-ci.org/manh-vv/eosjs-name)
[![codecov](https://codecov.io/gh/manh-vv/eosjs-name/branch/master/graph/badge.svg?token=WLVN5CZT6Q)](https://codecov.io/gh/manh-vv/eosjs-name)[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/manh-vv/eosjs-name)
```sh
npm i eosjs-account-name
``````sh
yarn add eosjs-account-name
``````html
```
Example of browser is in [index.html](./docs/index.html).
## From name to uint64
Here is [how eosio account name is computed to uint64](https://github.com/EOSIO/eos/blob/master/libraries/chain/include/eosio/chain/name.hpp#L21).
```text
"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
```javascript
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](./__tests__/symbol.test.js)
```javascript
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`](https://zelark.github.io/nano-id-cc/).
```javascript
const generate = require('nanoid/generate');
const alphabet = '.12345abcdefghijklmnopqrstuvwxyz';
generate(alphabet, 12); //=> "nc4zs1yyg.jx"
```