Skip to content

Instantly share code, notes, and snippets.

@DenisCarriere
Last active February 7, 2023 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DenisCarriere/0a99dd7b854dd3544494859d38320708 to your computer and use it in GitHub Desktop.
Save DenisCarriere/0a99dd7b854dd3544494859d38320708 to your computer and use it in GitHub Desktop.
Decode HEX data using Greymass EOSIO library
import { ABI, Serializer } from "@greymass/eosio";
const abi = ABI.from({
structs: [
{
name: "distribute_account",
base: "",
fields: [
{name: "account", type: "name"},
{name: "percent",type: "uint16"}
]
},
{
name: "setdistrib",
base: "",
fields: [
{name: "accounts", type: "distribute_account[]"}
]
},
{
name: "transfer",
base: "",
fields: [
{name: "from", type: "name"},
{name: "to", type: "name"},
{name: "quantity", type: "asset"},
{name: "memo", type: "string"}
]
}
],
})
function decode(data, type) {
const decoded = Serializer.decode({data, type, abi});
console.log(JSON.stringify(decoded));
}
decode("0180f3349701ea30551027", "setdistrib");
//=> {"accounts":[{"account":"eosio.grants","percent":10000}]}
decode("C0A6DB0603EA305580F3349701EA3055A054EAD70D00000004454F530000000000","transfer");
//=> {"from":"eosio.saving","to":"eosio.grants","quantity":"5945703.3376 EOS","memo":""}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment