Skip to content

Built-in Objects Reference


The UTXO_Compiler contract language provides two built-in objects: BVM and self. This document explains what they represent and how to use them in contracts.


1. self Object

  • Object Name: self
  • Description: Built-in object representing the current contract instance. self.X is replaced at compile time with a constant baked into the bytecode, so it is not subject to ownership rules and may be read repeatedly from any public or private function.
  • Example:
    python
    # Use self to access contract member variables
    Contract P2PKH:
        def verify(sig: hex, pubKey: hex):
            pubKey_copy = pubKey.Clone()
            pubKeyHash = Hash160(pubKey_copy)
            EqualVerify(pubKeyHash, self.pubKeyHash)   # check the stored hash for this instance
            Return CheckSig(sig, pubKey)

2. BVM Object

  • Object Name: BVM (Bytecode Virtual Machine)
  • Description: A built-in object representing the bytecode virtual machine, providing access to VM metadata such as version, input/output counts.
  • Predefined Member Mapping Table:
    Member NameCorresponding ValuePurpose
    "version"1VM version number
    "locktime"2Lock time
    "inputCount"3Number of inputs
    "outputCount"4Number of outputs
    "inputsHash"5Hash of input data
    "unlockingInput"6Unlocking input data
    "outputsHash"7Hash of output data
  • Example:
    python
    # Process transaction data and verify
    tx_data = Cat(pretx.VLIO, tx_data)  # concatenate transaction data
    txid = Hash256(tx_data)  # compute transaction ID
    
    # Access BVM object metadata
    meta_data = BVM.unlockingInput  # get unlocking input metadata
    {meta_data_txid, meta_data_remain} = Split(meta_data, 32)  # extract transaction ID from metadata
    
    EqualVerify(txid, meta_data_txid)  # verify transaction ID consistency

Beginner Pitfalls

  • Treating self as runtime storage: self.X is written into bytecode at compile time, not mutable on-chain storage.
  • Forgetting transaction context during local debugging: contracts that read BVM.* need simulated data from settxfile.
  • Checking only one output field: when current outputs matter, use BVM.outputsHash for the aggregate commitment.

Quick Review

  • self represents the current contract instance and is commonly used for deployment-time instance data.
  • self.X is replaced into bytecode at compile time and can be read repeatedly.
  • BVM exposes transaction-context data available during script execution.
  • BVM.outputsHash is commonly used to verify that current transaction outputs match contract rules.
  • Contracts that read BVM.* need simulated transaction data when debugged locally.

Next Steps


🇨🇳 中文版