Script

class blsct.Script(obj: Any = None)

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.

>>> from blsct import ChildKey, DoublePublicKey, OutPoint, PublicKey, Scalar, SubAddr, SubAddrId, TokenId, CTX_ID_SIZE, CTx, CTxId, TxIn, TxOut, Script
>>> import secrets
>>> num_tx_in = 1
>>> num_tx_out = 1
>>> default_fee = 200000
>>> fee = (num_tx_in + num_tx_out) * default_fee
>>> out_amount = 10000
>>> in_amount = fee + out_amount
>>> ctx_id = CTxId.deserialize(secrets.token_hex(32))
>>> out_point = OutPoint(ctx_id)
>>> gamma = 100
>>> spending_key = Scalar()
>>> token_id = TokenId()
>>> tx_in = TxIn(in_amount, gamma, spending_key, token_id, out_point)
>>> sub_addr = SubAddr.from_double_public_key(DoublePublicKey())
>>> tx_out = TxOut(sub_addr, out_amount, 'navio')
>>> ctx = CTx([tx_in], [tx_out])
>>> ctx_outs = ctx.get_ctx_outs()
>>> script_pub_key = ctx_outs[0].get_script_pub_key()
>>> ser = script_pub_key.serialize()
>>> deser = Script.deserialize(ser)
>>> ser == deser.serialize()
True
classmethod deserialize(hex: str) → Self

Deserialize the Script from a hexadecimal string

serialize() → str

Serialize the Script to a hexadecimal string