Last active
April 2, 2021 02:25
-
-
Save conr2d/0c942c4a902006293237c9a9f327b612 to your computer and use it in GitHub Desktop.
Simple conversion between name and uint64 with eosjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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