Skip to content

TypeScript SDK VM And Transaction APIs

This page covers the public TypeScript APIs for keys, addresses, VM scripts, transactions, binary helpers, VM object decoding, and event helpers.

Keys, Addresses, And Signatures

APIPurpose
PhantasmaKeys.generate()Creates a random Ed25519 key pair.
PhantasmaKeys.fromWIF(wif)Imports a WIF private key.
keys.privateKey, keys.publicKey, keys.addressCanonical key accessors.
keys.toWIF()Exports WIF.
keys.sign(message)Signs a byte array.
Address.fromText(text) / Address.parse(text)Parses address text.
Address.fromPublicKey(publicKey)Builds a user address from a public key.
Address.nullAddressNull address singleton.
Address.isValidAddress(text)Boolean validation helper.
Ed25519Signature.verify(message, address)Verifies one signature.

PascalCase address/key aliases remain for compatibility and are marked deprecated in the type declarations.

ScriptBuilder

ScriptBuilder is a chainable VM script builder. Use ScriptBuilder.create() or new ScriptBuilder().

APIPurpose
beginScript()Starts a script chain.
getScript()Returns current script hex.
endScript()Appends RET and returns final script hex.
emit(...), emitPush, emitPop, emitExtCall, emitLoad...Low-level opcode and value emitters.
emitLabel, emitJump, emitCall, emitConditionalJumpLabel and branch helpers.
callInterop(method, args)Emits a VM interop call.
callContract(contractName, method, args)Emits a contract call.
allowGas, spendGasGas helpers.
mintTokens, transferTokens, transferBalance, transferNftToken helpers.
crossTransferToken, crossTransferNftEmit Runtime.SendTokens and Runtime.SendToken. The chain has no such interops, and a script that calls one faults.
stake, unstake, callNftStake and NFT helpers.
appendHexEncoded(bytes)Appends already-encoded bytecode.

Deprecated PascalCase aliases remain for older consumers and are planned for removal at v1.0.

Transaction

Transaction represents a script transaction.

APIPurpose
new Transaction(nexusName, chainName, script, expiration, payload)Creates an unsigned transaction.
Transaction.fromHex(serializedData)Parses serialized hex.
Transaction.fromBytes(serializedData)Parses serialized bytes.
sign(wif), signWithPrivateKey(privateKey), signWithKeys(keys)Signing helpers.
verifySignature(address) / verifySignatures(addresses)Signature checks.
getUnsignedBytes()Returns unsigned transaction bytes.
toByteArray(withSignature)Serializes to bytes.
toString(withSignature)Serializes to hex.
toStringEncoded(withSignature)Serializes bytes with Base16 encoding.
getHash()Computes and stores transaction hash.
mineTransaction(difficulty)Mutates transaction payload for proof of work.
deserialize(serialized)Static deserializer for bytes.

Use toStringEncoded(true) for sendRawTransaction only after the transaction has the required signatures (toString(true) is a deprecated alias).

VM Objects And Event Helpers

APIPurpose
VMObject, VMType, decodeVMObjectVM result decoding and typed conversion.
DecoderScript/result decoder helper.
OpcodeVM opcode enum.
getTokenEventData, getGasEventData, getMarketEventData, getInfusionEventData, getChainValueEventData, getTransactionSettleEventDataEvent data decoders.

Binary And Utility Helpers

APIPurpose
PBinaryReader, PBinaryWriterVM binary format reader/writer.
CarbonBinaryReader, CarbonBinaryWriterCarbon wire-format reader/writer.
Base16, bytesToHex, hexToBytes, decodeBase16, encodeBase16Hex helpers.
bigIntToTwosComplementLE, twosComplementLEToBigIntInteger encoding helpers.
getDifficultyProof-of-work difficulty helper.
isValidIdentifier, isReservedIdentifier, isValidTickerNaming validators.