Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

dfuse Decode Hex Data (using eosjs)

This quick repository showcase how to decode hexadecimal string data into a JSON structure.

To accomplish that, we fetch the right ABI type from a particular contract, one that encoded the given data. From the ABI, we extract the type we want to deserialize.

We then use eosjs to deserialize the hexadecimal data into a JSON string value directly.

To run the example, clone this repository, then code at the root of the project then:

yarn install
yarn run ts-node index.ts


Sample code recopied here as a quick reference.

import { Api, JsonRpc } from 'eosjs';
import fetch from 'node-fetch'
import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig';
import { getTypesFromAbi, createInitialTypes, hexToUint8Array, SerialBuffer } from 'eosjs/dist/eosjs-serialize';
import { TextEncoder, TextDecoder } from 'util';

async function main(): Promise<void> {
    const signatureProvider = new JsSignatureProvider([]);
    const rpc = new JsonRpc('', { fetch: fetch as any });
    const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder() as any, textEncoder: new TextEncoder() });

    const abi = await api.getAbi("eosio.token")

    const builtinTypes = createInitialTypes()
    const types = getTypesFromAbi(builtinTypes, abi)

    const hexData = "000090e602ea30550000000000ea3055a08601000000000004454f530000000005656f736a73"
    const data = hexToUint8Array(hexData);

    const buffer = new SerialBuffer({ textDecoder: new TextDecoder() as any, textEncoder: new TextEncoder() });

    // You would use the struct representing the table row in your own code
    const transferType = types.get("transfer")
    if (transferType === undefined) {
        console.log("Type 'transfer' does not exist on 'eosio.token' ABI")

    const transfer = transferType.deserialize(buffer);

    console.log("Deserialized hex data")
    console.log(` From: ${transfer.from}`)
    console.log(` To: ${}`)
    console.log(` Quantity: ${transfer.quantity}`)
    console.log(` Memo: ${transfer.memo}`)

main().then(() => {
}).catch((error) => {
    console.log("An error occurred", error)
You can’t perform that action at this time.