Transactions

Transaction class defines VeChain’s multi-clause transaction (tx).

This module defines data structure of a transaction, and the encoding/decoding of transaction data.

Classes:

Transaction

Multi-clause transaction.

Type or structure checkers:

ClauseT

Type of transaction clause.

ReservedT

Type of reserved transaction field.

TransactionBodyT

Type of transaction body.

CLAUSE

Validation Schema for transaction clause.

RESERVED

Validation Schema for reserved transaction field.

BODY

Validation Schema for transaction body.

Data:

UnsignedTxWrapper

Unsigned transaction wrapper.

SignedTxWrapper

Signed transaction wrapper.

Functions:

data_gas

Calculate the gas the data will consume.

intrinsic_gas

Calculate roughly the gas from a list of clauses.

class thor_devkit.transaction.Transaction(body: thor_devkit.transaction.TransactionBodyT)[source]

Bases: object

Multi-clause transaction.

Attributes:

DELEGATED_MASK

Mask for delegation bit.

body

Get a dict of the body that represents the transaction.

intrinsic_gas

Roughly estimate amount of gas this transaction will consume.

signature

Signature of transaction.

origin

Transaction origin.

delegator

Transaction delegator.

is_delegated

Check if this transaction is delegated.

id

Transaction id.

Methods:

copy_body

Get a deep copy of transaction body.

get_signing_hash

Get signing hash (with delegate address if given).

encode

Encode the tx into bytes.

decode

Create a Transaction type instance from encoded bytes.

Deprecated:

get_delegator

Get delegator.

get_intrinsic_gas

Get intrinsic gas estimate.

get_signature

Get signature.

set_signature

Set signature.

get_origin

Get origin.

get_id

Get transaction ID.

get_body

Get a dict of the body that represents the transaction.

Construct a transaction from a given body.

DELEGATED_MASK: Final = 1

Mask for delegation bit.

The reserved feature of delegated (vip-191) is 1.

property body: thor_devkit.transaction.TransactionBodyT

Get a dict of the body that represents the transaction.

copy_body() thor_devkit.transaction.TransactionBodyT[source]

Get a deep copy of transaction body.

get_signing_hash(delegate_for: Optional[str] = None) bytes[source]

Get signing hash (with delegate address if given).

property intrinsic_gas: int

Roughly estimate amount of gas this transaction will consume.

New in version 2.0.0.

property signature: Optional[bytes]

Signature of transaction.

New in version 2.0.0.

property origin: Optional[str]

Transaction origin.

New in version 2.0.0.

property delegator: Optional[str]

Transaction delegator.

New in version 2.0.0.

property is_delegated: bool

Check if this transaction is delegated.

Changed in version 2.0.0: is_delegated is a property now.

property id: Optional[str]

Transaction id.

New in version 2.0.0.

encode(force_unsigned: bool = False) bytes[source]

Encode the tx into bytes.

static decode(raw: bytes, unsigned: bool) thor_devkit.transaction.Transaction[source]

Create a Transaction type instance from encoded bytes.

get_delegator() Optional[str][source]

Get delegator.

Deprecated since version 2.0.0: Use delegator property instead.

get_intrinsic_gas() int[source]

Get intrinsic gas estimate.

Deprecated since version 2.0.0: Use intrinsic_gas property instead.

get_signature() Optional[bytes][source]

Get signature.

Deprecated since version 2.0.0: Use signature property instead.

set_signature(sig: bytes) None[source]

Set signature.

Deprecated since version 2.0.0: Use signature property setter instead.

get_origin() Optional[str][source]

Get origin.

Deprecated since version 2.0.0: Use origin property instead.

get_id() Optional[str][source]

Get transaction ID.

Deprecated since version 2.0.0: Use id property instead.

get_body(as_copy: bool = True) thor_devkit.transaction.TransactionBodyT[source]

Get a dict of the body that represents the transaction.

Deprecated since version 2.0.0: Use body() or copy_body() instead.

Parameters

as_copy (bool, default: True) – Return a new dict clone of the body

Returns

If as_copy, return a newly created dict. If not, return the body of this Transaction object.

Return type

TransactionBodyT

class thor_devkit.transaction.ClauseT[source]

Bases: TypedDict

Type of transaction clause.

New in version 2.0.0.

to: Optional[str]

Transaction target contract, or None to create new one.

value: Union[str, int]

Amount to be paid (integer or its hex representation with 0x).

data: str

VET to pass to the call.

class thor_devkit.transaction.ReservedT[source]

Bases: TypedDict

Type of reserved transaction field.

New in version 2.0.0.

features: int

Integer (8 bit) with features bits set.

unused: Sequence[bytes]

Unused reserved fields.

class thor_devkit.transaction.TransactionBodyT[source]

Bases: TypedDict

Type of transaction body.

New in version 2.0.0.

chainTag: int

Last byte of genesis block ID

blockRef: str

Block reference, 0x...-like hex string (8 bytes).

First 4 bytes are block height, the rest is part of referred block ID.

expiration: int

Expiration (relative to blockRef, in blocks)

clauses: Sequence[thor_devkit.transaction.ClauseT]

Transaction clauses.

gasPriceCoef: int

Coefficient to calculate gas price.

gas: Union[int, str]

Maximum of gas to be consumed (int or its hex representation with 0x).

dependsOn: Optional[str]

Address of transaction on which current transaction depends.

nonce: Union[int, str]

Transaction nonce (int or its hex representation with 0x).

reserved: typing_extensions.NotRequired[thor_devkit.transaction.ReservedT]

Reserved field.

thor_devkit.transaction.CLAUSE(data): Final

Validation Schema for transaction clause.

Changed in version 2.0.0: Added validation of to, value and data as hex string.

thor_devkit.transaction.RESERVED(data): Final

Validation Schema for reserved transaction field.

thor_devkit.transaction.BODY(data): Final

Validation Schema for transaction body.

Changed in version 2.0.0: Added validation of gas, dependsOn and nonce fields as hex string.

thor_devkit.transaction.UnsignedTxWrapper: Final

Unsigned transaction wrapper.

thor_devkit.transaction.SignedTxWrapper: Final

Signed transaction wrapper.

thor_devkit.transaction.data_gas(data: str) int[source]

Calculate the gas the data will consume.

Parameters

data (str) – 0x... style hex string.

Returns

Estimated gas consumption.

Return type

int

thor_devkit.transaction.intrinsic_gas(clauses: Sequence[thor_devkit.transaction.ClauseT]) int[source]

Calculate roughly the gas from a list of clauses.

Parameters

clauses (Sequence[ClauseT]) – A list of clauses (in dict format).

Returns

The amount of gas.

Return type

int