Skip to content

Instantly share code, notes, and snippets.

@conr2d
Last active April 2, 2021 02:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conr2d/0c942c4a902006293237c9a9f327b612 to your computer and use it in GitHub Desktop.
Save conr2d/0c942c4a902006293237c9a9f327b612 to your computer and use it in GitHub Desktop.
Simple conversion between name and uint64 with eosjs
import { Serialize } from 'eosjs';
const types = Serialize.createInitialTypes();
const nameToUint64 = (name: string): string => {
let ser = new Serialize.SerialBuffer();
ser.pushName(name);
return types.get('uint64').deserialize(ser);
};
const uint64ToName = (num: string): string => {
let ser = new Serialize.SerialBuffer();
types.get('uint64').serialize(ser, num);
return ser.getName();
}
const eosioNum = nameToUint64('eosio');
console.log(eosioNum);
console.log(uint64ToName(eosioNum));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment