Last active
February 7, 2023 05:38
-
-
Save DenisCarriere/0a99dd7b854dd3544494859d38320708 to your computer and use it in GitHub Desktop.
Decode HEX data using Greymass EOSIO library
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 { 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