navio-blsct
    Preparing search index...

    Class Script

    Represents a script, which may be a scriptPubKey, scriptSig, or scriptWitness. Also known as CScript on the C++ side.

    A Script appears as an attribute of CTxOut (scriptPubKey) or CTxIn (scriptSig and scriptWitness), and is not meant to be instantiated directly.

    Examples:

    const { CTx, CTxId, TxIn, TxOut, OutPoint, SubAddr, DoublePublicKey, SpendingKey, TokenId, Script, CTX_ID_SIZE } = require('navio-blsct')
    const { randomBytes } = require('crypto')
    const numTxIn = 1
    const numTxOut = 1
    const defaultFee = 200000
    const fee = (numTxIn + numTxOut) * defaultFee
    const outAmount = 10000
    const inAmount = fee + outAmount
    const cTxIdHex = randomBytes(CTX_ID_SIZE).toString('hex')
    const cTxId = CTxId.deserialize(cTxIdHex)
    const outIndex = 0
    const outPoint = OutPoint.generate(cTxId, outIndex)
    const gamma = 100
    const spendingKey = SpendingKey.random()
    const tokenId = TokenId.default()
    const txIn = TxIn.generate(inAmount, gamma, spendingKey, tokenId, outPoint)
    const subAddr = SubAddr.fromDoublePublicKey(DoublePublicKey.random())
    const txOut = TxOut.generate(subAddr, outAmount, 'navio')
    const cTx = CTx.generate([txIn], [txOut])
    const cTxOuts = cTx.getCTxOuts()
    const scriptPubKey = cTxOuts[0].getScriptPubKey()
    const ser = scriptPubKey.serialize()
    const deser = Script.deserialize(ser)
    deser.serialize() === ser // true

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    obj: any
    objSize: number

    Methods

    • Returns the underlying C++ object, transferring ownership from this instance to the caller.

      Returns any

      The underlying object of the instance.

    • Serializes the instance to a hexadecimal string.

      Returns string

      A hexadecimal string representation of the instance.

    • Returns the size of the underlying C++ object.

      Returns number

      The size of the underlying C++ object in bytes.

    • Returns a string representation of the instance.

      Returns string

      A string representation of the instance.

    • Deserializes a Script from its hexadecimal representation.

      Parameters

      • this: new (obj: any) => Script
      • hex: string

        The hexadecimal string to deserialize.

      Returns Script

      A new Script instance.

    • Constucts a new instance using the provided object.

      Type Parameters

      Parameters

      • this: new (obj: any, objSize?: number) => T
      • obj: any

        The object to use for the new instance.

      Returns T

      A new instance of the class.

    • Constructs a new instance using the provided object and size.

      Type Parameters

      Parameters

      • this: new (obj: any) => T
      • obj: any

        The object to use for the new instance.

      • objSize: number

        The size of the object.

      Returns T

      A new instance of the class.