Skip to content
pha-decode

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_Raw wrappers 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[].data of a transaction result.
  • ROM blobs in auto, legacy/common, or CROWN mode.
  • Serialized VM objects, such as the result of an invokeRawScript RPC call.
  • Carbon bytes32 addresses 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 build

Quick 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 call

Decode an event payload:

pha-decode event --hex 0xAABBCC... --kind TokenMint

Decode ROM:

pha-decode rom --hex 0x... --symbol CROWN --token-id 80367770225206466995541877216191568684251978941303868068127874072614271067693

Decode a serialized VM object:

pha-decode vmobj 0x03010B

Convert addresses:

pha-decode address --bytes32 f100396a4b73e3abcd6b9039712944d7df9e8abe7211e519a91176e83a28d01b
pha-decode address --pha P2KKzrLNZK75f4Vtp4wwWocfgoqywBo3zKBWxBXjLgbxXmL

Commands and inputs

pha-decode supports five commands:

  • tx (default): decode a transaction. Provide it as raw hex (--hex), fetch it by hash (--hash with --rpc), pass an RPC transaction JSON (--rpc-json <path|->), or decode a Carbon transaction body (--carbon-tx-data with --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 --hex or 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 0x prefix and must have even length.
  • tx mode takes exactly one input: --hex, --hash, --carbon-tx-data, or --rpc-json.
  • --hash requires --rpc.
  • In tx mode, --resolve requires --rpc.
  • --carbon-tx-data requires --carbon-tx-type. --carbon-tx-type is valid only with --carbon-tx-data.
  • --payload, --expiration, --gas-payer, --gas-limit, and --signature-count are valid only with --carbon-tx-data.
  • event mode requires --hex.
  • rom mode requires --hex.
  • vmobj mode requires exactly one hex input.
  • address mode requires exactly one address input selector. Use --stdin with 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.
  • --resolve Fetch 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.
  • --verbose Enable SDK logging.
  • --help Show help.
  • --version Show the package version.

Transaction input:

  • --hex <hex> Carbon SignedTxMsg, full VM transaction, or raw VM script hex. In event, rom, and vmobj mode, --hex carries the input of that mode.
  • --hash <hash> Transaction hash to fetch with getTransaction. Requires --rpc.
  • --rpc-json <path|-> A getTransaction result object or a JSON-RPC response that holds it in result. - reads standard input.
  • --carbon-tx-data <hex> The payload-only carbonTxData field of an RPC transaction. Requires --carbon-tx-type.
  • --carbon-tx-type <number|name> Carbon transaction type as a number from 0 to 255 or as a TxTypes name, for example 15 or Phantasma.
  • --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.

Carbon output detail:

  • --carbon-detail <all|call|msg|none> Control Carbon output (default: call).
  • --carbon-addresses <bytes32|pha> Render known Carbon address fields as raw bytes32 or decoded Phantasma addresses (default: bytes32).
    • Accepted aliases: raw, hex, off -> bytes32; phantasma, decode -> pha.

Event decoding:

  • --kind <eventKind> Event kind hint for the event payload. Accepts numeric id or name.

ROM decoding:

  • --symbol <symbol> ROM symbol hint, for example CROWN.
  • --token-id <tokenId> ROM token id hint.
  • --rom-format <auto|legacy|crown> ROM parser mode (default: auto). common is accepted as an alias for legacy.

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.
  • --stdin Read 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-addresses are ignored.
  • If --kind is 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 --kind are 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 --kind are ignored.
  • A decode failure is reported in errors and the process exits with code 1.

When address is selected:

  • --abi, --resolve, --vm-detail, --carbon-detail, --carbon-addresses, --rpc, --kind, --hex, --symbol, and --token-id are ignored.
  • --index applies only to a modern seed phrase (--mnemonic or --seed-phrase). With any other input it is ignored.
  • --legacy-password applies only to a legacy seed phrase (--mnemonic-legacy). With any other input it is ignored.
  • Secret inputs are redacted from CLI output. Prefer --stdin for 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.
  • --resolve uses the RPC getContracts output 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:

IdVM typeDecoded form
0Nonevalue is null.
1Structentries 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.
2Bytesvalue is a hex string.
3Numbervalue is a signed decimal string.
4Stringvalue is a UTF-8 string.
5Timestampvalue is an unsigned 32-bit integer.
6Boolvalue is true or false.
7Enumvalue is an integer.
8Objectvalue 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).

IdName
0Unknown
1ChainCreate
2TokenCreate
3TokenSend
4TokenReceive
5TokenMint
6TokenBurn
7TokenStake
8TokenClaim
9AddressRegister
10AddressLink
11AddressUnlink
12OrganizationCreate
13OrganizationAdd
14OrganizationRemove
15GasEscrow
16GasPayment
17AddressUnregister
18OrderCreated
19OrderCancelled
20OrderFilled
21OrderClosed
22FeedCreate
23FeedUpdate
24FileCreate
25FileDelete
26ValidatorPropose
27ValidatorElect
28ValidatorRemove
29ValidatorSwitch
30PackedNFT
31ValueCreate
32ValueUpdate
33PollCreated
34PollClosed
35PollVote
36ChannelCreate
37ChannelRefill
38ChannelSettle
39LeaderboardCreate
40LeaderboardInsert
41LeaderboardReset
42PlatformCreate
43ChainSwap
44ContractRegister
45ContractDeploy
46AddressMigration
47ContractUpgrade
48Log
49Inflation
50OwnerAdded
51OwnerRemoved
52DomainCreate
53DomainDelete
54TaskStart
55TaskStop
56CrownRewards
57Infusion
58Crowdsale
59OrderBid
60ContractKill
61OrganizationKill
62MasterClaim
63ExecutionFailure
64Custom
65Custom_V2
66GovernanceSetGasConfig
67GovernanceSetChainConfig
68TokenSeriesCreate
69SpecialResolution