Skip to content

Python SDK API Overview

This page summarizes the current Python SDK public surface and links to the complete reference pages for detailed RPC methods, result fields, wire structures, and low-level helpers.

For the deeper API material, use the complete API reference:

Package

ItemValue
Packagephantasma-sdk-py
Import namespacephantasma_py
Current source version4.0.1
Python>=3.11

Top-Level Imports

The package re-exports the most common classes and helpers from phantasma_py.

from phantasma_py import (
    Address,
    PhantasmaKeys,
    PhantasmaRPC,
    ScriptBuilder,
    Transaction,
)

For larger applications, importing from the module that owns the API keeps code clearer:

from phantasma_py.carbon import build_create_token_tx_and_sign_hex
from phantasma_py.rpc import PhantasmaRPC

phantasma_py.crypto

APIPurpose
AddressChecked 34-byte Phantasma address with from_text, from_public_key, from_hash, null, text, kind, and public_key.
PhantasmaKeysEd25519 key pair with private_key, generate, from_wif, to_wif, public_key, address, and sign.
Ed25519SignatureSignature wrapper with verify and serialize_data.
HashSHA-256 hash wrapper with from_hex, sha256, hex, and difficulty.
AddressKind, SignatureKindTyped enums for address and signature kinds.

See Keys And Addresses for WIF, signing, address parsing, and Carbon Bytes32 conversion examples.

Details: VM and Transaction APIs.

phantasma_py.vm

APIPurpose
ScriptBuilderChainable VM script builder.
OpcodeVM opcode enum.
VMObjectVM object decoding and typed conversion.
VMTypeVM object type enum.

Common ScriptBuilder methods include call_interop, call_contract, allow_gas, spend_gas, transfer_tokens, transfer_nft, stake, unstake, call_nft, end_script, end_script_hex, and end_script_with_error.

Method and helper reference: VM and Transaction APIs.

phantasma_py.transaction

APIPurpose
TransactionVM script transaction with to_bytes, from_bytes, hash, sign, is_signed_by, and mine.
tx_state_is_successReturns true for HALT.
tx_state_is_faultReturns true for FAULT or BREAK.

phantasma_py.encoding, phantasma_py.binary, And phantasma_py.errors

ModuleAPIPurpose
encodingencode_base58, decode_base58Base58 helpers used by address and WIF parsing.
encodingencode_hex, decode_hexHex helpers. decode_hex trims whitespace and accepts an optional 0x/0X prefix.
binaryBinaryWriter, BinaryReaderVM binary writer/reader for scripts, VM objects, and script transactions.
binarybig_int_to_vm_bytes, vm_bytes_to_big_intPhantasma VM bigint conversion helpers.
errorsPhantasmaError and subclassesSDK exception hierarchy used by RPC, crypto, encoding, serialization, and builder code.

phantasma_py.rpc

APIPurpose
JsonRpcClientLow-level JSON-RPC client.
PhantasmaRPCTyped RPC facade.
Result dataclassesAccountResult, BlockResult, TransactionResult, TokenResult, TokenDataResult, TokenSeriesResult, ScriptResult, and related RPC models.

PhantasmaRPC exposes read wrappers, invoke-script wrappers, and send helpers. See RPC for workflow usage, RPC Methods for signatures, and RPC Models for result fields.

phantasma_py.carbon

APIPurpose
CarbonWriter, CarbonReaderCarbon wire-format primitives.
Bytes16, Bytes32, Bytes64, SmallString, IntXChecked Carbon primitive types.
CarbonVMTypeTop-level alias for phantasma_py.carbon.VMType; use it when code also imports phantasma_py.vm.VMType.
serialize, deserializeGeneric Carbon round-trip helpers.
TokenInfo, SeriesInfo, TokenSchemasToken and schema structures.
TokenSchemaField, TokenSchemasJSON, VMStructSchema, VMDynamicStruct, VMDynamicVariableSchema and metadata structures used by token series, ROM, and RAM.
TxMsg, SignedTxMsg, WitnessCarbon transaction message structures.
build_token_metadata, build_token_info, prepare_standard_token_schemasMetadata and schema helpers.
token_schemas_from_json, parse_token_schemas_json, build_token_schemas_from_fields, verify_token_schemasCustom schema parsing and validation helpers.
build_create_token_tx, build_create_token_series_tx, build_mint_phantasma_non_fungible_txToken lifecycle transaction builders.
build_transfer_fungible_tx, build_transfer_non_fungible_tx, build_mint_fungible_tx, build_burn_fungible_tx, build_burn_non_fungible_txNative transfer, mint and burn builders, which need no VM script.
sign_tx_msg, sign_and_serialize_tx_msg, sign_and_serialize_tx_msg_hexCarbon transaction signing helpers.
plan_fees, FeePlan, FeePlanOptions, summarize_fee_plan, burned_instances, TxLimits, expiry_withinFee planning from the message and the chain’s gas configuration.
Result parsersparse_create_token_result, parse_create_token_series_result, parse_mint_non_fungible_result, parse_mint_phantasma_non_fungible_result.

The Carbon module also exposes module-call argument structs for token, market, chain, gas, and tokens configuration flows.

See Schemas And Metadata, Fees And Broadcasting, and Carbon Operations for usage examples and workflow guidance.

Carbon type and builder reference: Carbon API and Wire Format.

Exceptions

All SDK-specific exceptions inherit from PhantasmaError.

ExceptionRaised by
EncodingErrorBase58/hex and binary encoding failures.
SerializationErrorVM or Carbon serialization failures.
CryptoErrorAddress, key, WIF, hash, and signature failures.
RPCErrorJSON-RPC transport or RPC response failures.
BuilderErrorScript builder and Carbon builder validation failures.