pha-decode
CLI tool for decoding Phantasma Carbon and VM transactions, contract lifecycle scripts, event payload hex, ROM blobs, serialized VM objects, and address conversions.
What it can decode
- Carbon transaction hex or a transaction fetched by hash.
- Carbon
Phantasma/Phantasma_Rawwrappers reconstructed into a VM view. - VM transaction containers and raw VM scripts, including disassembly and method calls.
- Deploy / upgrade interops with contract name, signer, script hash, ABI hash, and ABI method/event summaries when ABI bytes are present.
- Event payload hex, as carried by
events[].dataof a transaction result. - ROM blobs in auto, legacy/common, or
CROWNmode. - Serialized VM objects, such as the
resultof aninvokeRawScriptRPC call. - Carbon
bytes32addresses to Phantasma addresses and back. - Phantasma address derivation from WIF, a 32-byte private key, modern BIP44 seed phrases, or legacy Poltergeist seed phrases.
- JSON or pretty text output.
- Optional ABI resolution from local files or RPC.
Requirements
- Node.js with ESM support (Node
>=22).
Installation
# install globally
npm i -g pha-decode
# or run once via npx
npx pha-decode --help
npx pha-decode --version
# local dev install
npm install
npm run buildQuick start
Decode a local transaction hex (shorthand):
pha-decode 0xDEADBEEF...Decode a transaction hash from RPC:
pha-decode tx --hash 155422A6882C3342933521DDC1A335292BF6448DBD489ED0BE21CFC74AFBA52A \
--rpc https://pharpc1.phantasma.info/rpc \
--format json \
--vm-detail calls \
--carbon-detail callDecode an event payload:
pha-decode event --hex 0xAABBCC... --kind TokenMintDecode ROM:
pha-decode rom --hex 0x... --symbol CROWN --token-id 80367770225206466995541877216191568684251978941303868068127874072614271067693Decode a serialized VM object:
pha-decode vmobj 0x03010BConvert addresses:
pha-decode address --bytes32 f100396a4b73e3abcd6b9039712944d7df9e8abe7211e519a91176e83a28d01b
pha-decode address --pha P2KKzrLNZK75f4Vtp4wwWocfgoqywBo3zKBWxBXjLgbxXmLCommands and inputs
pha-decode supports five commands:
tx(default): decode a transaction. Provide it as raw hex (--hex), fetch it by hash (--hashwith--rpc), pass an RPC transaction JSON (--rpc-json <path|->), or decode a Carbon transaction body (--carbon-tx-datawith--carbon-tx-type). Optional context for--carbon-tx-data:--payload,--expiration,--gas-payer,--gas-limit,--signature-count.event: decode an event payload from hex (--hex) with an optional event kind (--kind).rom: decode ROM hex (--hex) with optional--symbol,--token-id, and--rom-format.vmobj: decode one serialized VM object from hex, passed as--hexor as a positional argument.address: convert or derive addresses from--bytes32,--pha,--wif,--private-key,--mnemonic, or--mnemonic-legacy.
Input rules:
- Hex strings may include
0xprefix and must have even length. txmode takes exactly one input:--hex,--hash,--carbon-tx-data, or--rpc-json.--hashrequires--rpc.- In
txmode,--resolverequires--rpc. --carbon-tx-datarequires--carbon-tx-type.--carbon-tx-typeis valid only with--carbon-tx-data.--payload,--expiration,--gas-payer,--gas-limit, and--signature-countare valid only with--carbon-tx-data.eventmode requires--hex.rommode requires--hex.vmobjmode requires exactly one hex input.addressmode requires exactly one address input selector. Use--stdinwith the selector to read secret input from standard input.
Output formats
--format controls output:
pretty(default): human readable sections.json: machine friendly output.
JSON output structure (example):
{
"source": "tx-hash",
"input": "155422A6...",
"format": "json",
"rpc": { "url": "https://...", "method": "getTransaction" },
"carbon": { "...": "..." },
"vm": { "...": "..." },
"event": { "...": "..." },
"rom": { "...": "..." },
"vmObject": { "...": "..." },
"address": { "...": "..." },
"warnings": [],
"errors": []
}Option reference
General:
--format <json|pretty>Output format (default:pretty).--rpc <url>RPC endpoint for--hash.--resolveFetch contract ABIs from RPC and merge into the method table.--abi <path>ABI JSON file or directory (merged with built-ins).--protocol <number>Protocol version used for ABI selection (default: latest known).--protocol-version <number>Alias for--protocol.--verboseEnable SDK logging.--helpShow help.--versionShow the package version.
Transaction input:
--hex <hex>CarbonSignedTxMsg, full VM transaction, or raw VM script hex. Inevent,rom, andvmobjmode,--hexcarries the input of that mode.--hash <hash>Transaction hash to fetch withgetTransaction. Requires--rpc.--rpc-json <path|->AgetTransactionresult object or a JSON-RPC response that holds it inresult.-reads standard input.--carbon-tx-data <hex>The payload-onlycarbonTxDatafield of an RPC transaction. Requires--carbon-tx-type.--carbon-tx-type <number|name>Carbon transaction type as a number from0to255or as aTxTypesname, for example15orPhantasma.--payload <hex>,--expiration <unix>,--gas-payer <address>,--gas-limit <amount>,--signature-count <n>Optional RPC context for--carbon-tx-data.
VM output detail:
--vm-detail <all|calls|ops|none>Control VM output (default:all).- Accepted aliases:
both->all,methods->calls,opcodes->ops,off->none.
- Accepted aliases:
Carbon output detail:
--carbon-detail <all|call|msg|none>Control Carbon output (default:call).--carbon-addresses <bytes32|pha>Render known Carbon address fields as rawbytes32or decoded Phantasma addresses (default:bytes32).- Accepted aliases:
raw,hex,off->bytes32;phantasma,decode->pha.
- Accepted aliases:
Event decoding:
--kind <eventKind>Event kind hint for the event payload. Accepts numeric id or name.
ROM decoding:
--symbol <symbol>ROM symbol hint, for exampleCROWN.--token-id <tokenId>ROM token id hint.--rom-format <auto|legacy|crown>ROM parser mode (default:auto).commonis accepted as an alias forlegacy.
Address decoding:
--bytes32 <hex>Carbon bytes32 address input.--pha <address>Phantasma address input.--wif <wif>WIF private-key input; redacted in output.--private-key <hex>32-byte private-key input; redacted in output.--mnemonic <words>/--seed-phrase <words>Modern BIP44 seed phrase input; redacted in output.--mnemonic-legacy <words>/--legacy-mnemonic <words>Legacy Poltergeist seed phrase input; redacted in output.--legacy-password <password>/--mnemonic-legacy-password <password>Optional legacy seed password; redacted in output.--stdinRead the selected address input from standard input.--index <n>/--derivation-index <n>Address derivation index for modern mnemonic input (default:0).
Mode rules
Ignored flags produce a warning in the output.
When event is selected:
--abi,--resolve,--vm-detail,--carbon-detail, and--carbon-addressesare ignored.- If
--kindis omitted or unknown, the tool returns raw hex with a warning.
When rom is selected:
--abi,--resolve,--vm-detail,--carbon-detail,--carbon-addresses,--rpc, and--kindare ignored.- Auto mode chooses a parser from the available context and falls back with warnings when needed.
When vmobj is selected:
--abi,--resolve,--vm-detail,--carbon-detail,--carbon-addresses,--rpc, and--kindare ignored.- A decode failure is reported in
errorsand the process exits with code1.
When address is selected:
--abi,--resolve,--vm-detail,--carbon-detail,--carbon-addresses,--rpc,--kind,--hex,--symbol, and--token-idare ignored.--indexapplies only to a modern seed phrase (--mnemonicor--seed-phrase). With any other input it is ignored.--legacy-passwordapplies only to a legacy seed phrase (--mnemonic-legacy). With any other input it is ignored.- Secret inputs are redacted from CLI output. Prefer
--stdinfor scripts and shells where history matters.
ABI resolution
The decoder starts with built-in ABI definitions. You can add more:
--abi <path>loads a JSON file or a directory of JSON files and merges into the method table.--resolveuses the RPCgetContractsoutput and merges contract methods.
If the RPC returns no contracts or a method is unknown, the decoder keeps raw hex values and adds warnings instead of guessing.
VM object decoding
vmobj decodes one serialized VM object. Use it on the result field of an invokeRawScript response, or on one item of its results array. vmobj does not decode VM scripts; pass a script to tx --hex.
pha-decode vmobj --hex 01020401610301010401620601 --format json{
"source": "vmobj-hex",
"input": "01020401610301010401620601",
"format": "json",
"vmObject": {
"vmTypeId": 1,
"vmType": "Struct",
"fields": { "a": "1", "b": true },
"entries": [
{ "keyVmType": "String", "key": "a", "valueVmType": "Number", "value": "1" },
{ "keyVmType": "String", "key": "b", "valueVmType": "Bool", "value": true }
]
},
"warnings": [],
"errors": []
}The vmObject node carries vmTypeId and vmType. The rest of the node depends on the type:
| Id | VM type | Decoded form |
|---|---|---|
| 0 | None | value is null. |
| 1 | Struct | entries lists every key and value with their VM types. fields is added as a plain object when every key is a String, Number, Enum, Timestamp, or Bool and no key repeats. |
| 2 | Bytes | value is a hex string. |
| 3 | Number | value is a signed decimal string. |
| 4 | String | value is a UTF-8 string. |
| 5 | Timestamp | value is an unsigned 32-bit integer. |
| 6 | Bool | value is true or false. |
| 7 | Enum | value is an integer. |
| 8 | Object | value is an object. When the bytes hold a serialized address, it has kind: "Address", text and bytesHex. Otherwise it has kind: "ObjectBytes" and bytesHex. |
Inside entries and fields, a nested struct is rendered as its fields object, or as its entry list when fields cannot be built. Other nested values are rendered as their plain value.
The decoder rejects an unknown VM type id and nesting deeper than 128 levels. Bytes left after the object produce a warning such as VM object has 2 trailing bytes.
Event kinds
--kind accepts either the numeric id or the name (case-insensitive, whitespace ignored).
| Id | Name |
|---|---|
| 0 | Unknown |
| 1 | ChainCreate |
| 2 | TokenCreate |
| 3 | TokenSend |
| 4 | TokenReceive |
| 5 | TokenMint |
| 6 | TokenBurn |
| 7 | TokenStake |
| 8 | TokenClaim |
| 9 | AddressRegister |
| 10 | AddressLink |
| 11 | AddressUnlink |
| 12 | OrganizationCreate |
| 13 | OrganizationAdd |
| 14 | OrganizationRemove |
| 15 | GasEscrow |
| 16 | GasPayment |
| 17 | AddressUnregister |
| 18 | OrderCreated |
| 19 | OrderCancelled |
| 20 | OrderFilled |
| 21 | OrderClosed |
| 22 | FeedCreate |
| 23 | FeedUpdate |
| 24 | FileCreate |
| 25 | FileDelete |
| 26 | ValidatorPropose |
| 27 | ValidatorElect |
| 28 | ValidatorRemove |
| 29 | ValidatorSwitch |
| 30 | PackedNFT |
| 31 | ValueCreate |
| 32 | ValueUpdate |
| 33 | PollCreated |
| 34 | PollClosed |
| 35 | PollVote |
| 36 | ChannelCreate |
| 37 | ChannelRefill |
| 38 | ChannelSettle |
| 39 | LeaderboardCreate |
| 40 | LeaderboardInsert |
| 41 | LeaderboardReset |
| 42 | PlatformCreate |
| 43 | ChainSwap |
| 44 | ContractRegister |
| 45 | ContractDeploy |
| 46 | AddressMigration |
| 47 | ContractUpgrade |
| 48 | Log |
| 49 | Inflation |
| 50 | OwnerAdded |
| 51 | OwnerRemoved |
| 52 | DomainCreate |
| 53 | DomainDelete |
| 54 | TaskStart |
| 55 | TaskStop |
| 56 | CrownRewards |
| 57 | Infusion |
| 58 | Crowdsale |
| 59 | OrderBid |
| 60 | ContractKill |
| 61 | OrganizationKill |
| 62 | MasterClaim |
| 63 | ExecutionFailure |
| 64 | Custom |
| 65 | Custom_V2 |
| 66 | GovernanceSetGasConfig |
| 67 | GovernanceSetChainConfig |
| 68 | TokenSeriesCreate |
| 69 | SpecialResolution |