Skip to content

Transaction

Meheret Tesfaye edited this page May 18, 2020 · 4 revisions

Transaction class

pybytom.transaction.Transaction

Bytom has only three networks mainnet, solonet and testnet.

Parameter

network (str) - Bytom network, [defaults to solonet].

Return

transaction (Transaction) - Bytom transaction class instance.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
<pybytom.transaction.transaction.Transaction object at 0x040DA268>

Build transaction

build_transaction() - Build Bytom transaction.

Parameter

kwargs (str) - Arbitrary keyword arguments. Make sure you link to documentation that describes what keywords are accepted, list the keyword arguments as a definition list:

  • guid (str) Bytom blockcenter guid, [required].
  • inputs (list) Bytom transaction inputs, [required].
  • outputs (list) bytom transaction outputs, [required].
  • fee (int) Bytom transaction fee, [defaults to 10000000].
  • confirmations (int) confirmations: Bytom transaction confirmations, [defaults to 1].

Return

transaction (Transaction) - Bytom transaction class instance.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction(guid="f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[[...], ...], outputs=[[...], ...], fee=10000000, confirmations=3)
<pybytom.transaction.transaction.Transaction object at 0x0409DAF0>

Get transaction fee

fee() - Bytom transaction fee.

Return

fee (int) - Bytom transaction fee.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[...], outputs=[...])
>>> transaction.fee()
10000000

Get transaction confirmations

confirmations() - Bytom transaction confirmations.

Return

confirmations (int) - Bytom transaction confirmations.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[...], outputs=[...])
>>> transaction.confirmations()
2

Get transaction hash

hash() - Bytom transaction hash.

Return

hash (str) - Bytom transaction hash.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[...], outputs=[...])
>>> transaction.hash()
"2993414225f65390220730d0c1a356c14e91bca76db112d37366df93e364a492"

Get transaction json

json() - Bytom transaction json.

Return

json (dict) - Bytom transaction json.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[...], outputs=[...])
>>> transaction.json()
{'hash': '2993414225f65390220730d0c1a356c14e91bca76db112d37366df93e364a492', 'status_fail': false, 'size': 379, 'submission_timestamp': 0, 'memo': "", 'inputs': [{'script': '00142cda4f99ea8112e6fa61cdd26157ed6dc408332a', 'address': 'bm1q9ndylx02syfwd7npehfxz4lddhzqsve2fu6vc7', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 2450000000, 'type': 'spend'}], 'outputs': [{'utxo_id': '5edccebe497893c289121f9e365fdeb34c97008b9eb5a9960fe9541e7923aabc', 'script': '01642091ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e220ac13c0bb1445423a641754182d53f0677cd4351a0e743e6f10b35122c3d7ea01202b9a5949f5546f63a253e41cda6bffdedb527288a7e24ed953f5c2680c70d6ff741f547a6416000000557aa888537a7cae7cac631f000000537acd9f6972ae7cac00c0', 'address': 'smart contract', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 1000, 'type': 'control'}, {'utxo_id': 'f8cfbb692db1963be88b09c314adcc9e19d91c6c019aa556fb7cb76ba8ffa1fa', 'script': '00142cda4f99ea8112e6fa61cdd26157ed6dc408332a', 'address': 'bm1q9ndylx02syfwd7npehfxz4lddhzqsve2fu6vc7', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 2439999000, 'type': 'control'}], 'fee': 10000000, 'balances': [{'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': '-10001000'}], 'types': ['ordinary']}

Get transaction raw

raw() - Bytom transaction raw.

Return

raw (str) - Bytom transaction raw.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[...], outputs=[...])
>>> transaction.raw()
"070100010160015e7f2d7ecec3f61d30d0b2968973a3ac8448f0599ea20dce883b48c903c4d6e87fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8091a0900901011600142cda4f99ea8112e6fa61cdd26157ed6dc408332a22012091ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e20201ad01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe80701880101642091ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e220ac13c0bb1445423a641754182d53f0677cd4351a0e743e6f10b35122c3d7ea01202b9a5949f5546f63a253e41cda6bffdedb527288a7e24ed953f5c2680c70d6ff741f547a6416000000557aa888537a7cae7cac631f000000537acd9f6972ae7cac00c000013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff98dcbd8b09011600142cda4f99ea8112e6fa61cdd26157ed6dc408332a00"

Get unsigned transaction datas

unsigned_datas() - Bytom unsigned transaction datas with signing instructions.

Return

unsigned_datas (dict) - Bytom transaction unsigned datas.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[...], outputs=[...])
>>> transaction.unsigned_datas()
[{'datas': ['a7ba7ffd969e4150b36ea9f1f861d53c6f69226a3519023899d27bf1f85be3d9'], 'public_key': '91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2', 'network': 'mainnet', 'path': 'm/44/153/1/0/1'}, {'datas': ['0dbf0e408099017711a941d9a9899541afa64eb31a7118815d37e6d603b7c329'], 'public_key': '91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2', 'network': 'mainnet', 'path': 'm/44/153/1/0/1'}]
>>> transaction.signatures()
[]

Sign unsigned transaction datas

sign() - Bytom sign unsigned transaction datas.

Parameter

xprivate_key (str) - Bytom xprivate key, [required].
account (int) - Bytom derivation account, [defaults to 1].
change (bool) - Bytom derivation change, [defaults to False].
address (int) - Bytom derivation address, [defaults to 1].
path (str) - Bytom derivation path, [defaults to None].
indexes (list) - Bytom derivation indexes, [defaults to None].

Return

transaction (Transaction) - Bytom transaction class instance.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[...], outputs=[...])
>>> transaction.unsigned_datas()
[{'datas': ['a7ba7ffd969e4150b36ea9f1f861d53c6f69226a3519023899d27bf1f85be3d9'], 'public_key': '91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2', 'network': 'mainnet', 'path': 'm/44/153/1/0/1'}, {'datas': ['0dbf0e408099017711a941d9a9899541afa64eb31a7118815d37e6d603b7c329'], 'public_key': '91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2', 'network': 'mainnet', 'path': 'm/44/153/1/0/1'}]
>>> transaction.sign(xprivate_key="3842e3fa2af2a687e7fd67655e7a02e85bbb4ca378d4338ff590dedc7ddff447797e1e781190835138c2d1a96d0e654b625a4c019cbc64f71100be7ad1b8d4ed")
>>> transaction.signatures()
[[...], ...]

Get signed transaction datas

signatures() - Bytom unsigned transaction datas with signing instructions.

Return

signatures (list) - Bytom signed transaction datas.

>>> from pybytom.transaction import Transaction
>>> transaction = Transaction(network="mainnet")
>>> transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", inputs=[...], outputs=[...])
>>> transaction.signatures()
[[...], ...]

Normal transaction class

pybytom.transaction.NormalTransaction

It inherited Transaction() class, but build_transaction function is different.

Parameter

network (str) - Bytom network, [defaults to solonet].

Return

normal_transaction (NormalTransaction) - Bytom normal transaction class instance.

>>> from pybytom.transaction import NormalTransaction
>>> normal_transaction = NormalTransaction(network="mainnet")
<pybytom.transaction.transaction.NormalTransaction object at 0x040DA268>

Build transaction

build_transaction() - Build Bytom normal transaction.

Parameter

guid (str) - Bytom sender blockcenter guid, [required].
recipients (dict) - Recipients Bytom address and amount, [required].

  • key (str) Bytom address, [required].
  • value (list) Bytom amount, [required].

asset (str) - Bytom asset id, [defaults to BTM asset].
fee (int) - Bytom transaction fee, [defaults to 10000000].
confirmations (int) - Bytom transaction confirmations, [defaults to 1].

Return

normal_transaction (NormalTransaction) - Bytom normal transaction class instance.

>>> from pybytom.transaction import NormalTransaction
>>> normal_transaction = NormalTransaction(network="mainnet")
>>> normal_transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", {"bm1qzx7pjr6whcaxmh9u0thkjuavf2ynk3zkgshhle": 10_000_000_000}, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
<pybytom.transaction.transaction.NormalTransaction object at 0x0409DAF0>       

Advanced transaction class

pybytom.transaction.AdvancedTransaction

It inherited Transaction() class and this is also the same with Transaction class, but when you are building transaction it checks the agreements ant not use kwargs.

Parameter

network (str) - Bytom network, [defaults to solonet].

Return

advanced_transaction (AdvancedTransaction) - Bytom advanced transaction class instance.

>>> from pybytom.transaction import AdvancedTransaction
>>> advanced_transaction = AdvancedTransaction(network="mainnet")
<pybytom.transaction.transaction.AdvancedTransaction object at 0x040DA268>

Build transaction

build_transaction() - Build Bytom advanced transaction.

Parameter

guid (str) - Bytom sender blockcenter guid, [required].
inputs (list) - Bytom transaction inputs, [required].
outputs (list) - Bytom transaction outputs, [required].
fee (int) - Bytom transaction fee, [defaults to 10000000].
confirmations (int) - Bytom transaction confirmations, [defaults to 1].

Return

advanced_transaction (AdvancedTransaction) - Bytom advanced transaction class instance.

>>> from pybytom.transaction import AdvancedTransaction
>>> advanced_transaction = AdvancedTransaction(network="mainnet")
>>> advanced_transaction.build_transaction("f0ed6ddd-9d6b-49fd-8866-a52d1083a13b", [[...], ...], outputs=[[...], ...], 10000000, 3)
<pybytom.transaction.transaction.AdvancedTransaction object at 0x0409DAF0>

Transaction Tools

pybytom.transaction.tools

Find contract UTXO id

find_contract_utxo_id() - Find Bytom smart contract UTXO id by transaction id/hash.

Parameter

transaction_id (str) - Bytom transaction id/hash, [required].
network (list) - Bytom network, [required].

Return

utxo_id (str) - Bytom unspent transaction output id/hash.

>>> from pybytom.transaction.tools import find_contract_utxo_id
>>> find_contract_utxo_id("e4d4fab70a41536cf298d6f261c0a1ac169a45be47583f7240115c9059cd0d03", "mainnet")
"169a45be47583f7240115c9059cd0d03e4d4fab70a41536cf298d6f261c0a1ac"

Get spend UTXO action

spend_utxo_action() - Get spend UTXO action.

Parameter

utxo (str) - Bytom unspent transaction output id/hash, [required].

Return

action (dict) - Bytom spend utxo action.

>>> from pybytom.transaction.tools import spend_utxo_action
>>> spend_utxo_action("169a45be47583f7240115c9059cd0d03e4d4fab70a41536cf298d6f261c0a1ac")
{'type': 'spend_utxo', 'output_id': '169a45be47583f7240115c9059cd0d03e4d4fab70a41536cf298d6f261c0a1ac'}

Get spend wallet action

spend_wallet_action() - Get spend wallet action.

Parameter

amount (int) - Bytom amount, [required].
asset (str) - Bytom asset, [required].

Return

action (dict) - Bytom spend wallet action.

>>> from pybytom.transaction.tools import spend_wallet_action
>>> spend_wallet_action(100000000, "41536cf298d6f261c0a1ac169a45be47583f7240115c9059cd0d03e4d4fab70a")
{'type': 'spend_wallet', 'amount': 100000000, 'asset': '41536cf298d6f261c0a1ac169a45be47583f7240115c9059cd0d03e4d4fab70a'}

Get spend account action

spend_account_action() - Get spend account action.

Parameter

account (str) - Bytom account, [required].
amount (int) - Bytom amount, [required].
asset (str) - Bytom asset, [required].

Return

action (dict) - Bytom spend account action.

>>> from pybytom.transaction.tools import spend_account_action
>>> spend_account_action(bytom_account, bytom_amount, bytom_asset)
{type: 'spend_account', account='...', amount=1000000, asset='...'}

Get contract arguments action

contract_arguments_action() - Get contract arguments action.

Parameter

amount (int) - Bytom amount, [required].
address (str) - Bytom address, [required].
value (str) - Data value, [default to None].

Return

action (list) - Bytom contract arguments action.

>>> from pybytom.transaction.tools import contract_arguments_action
>>> contract_arguments_action(bytom_amount, bytom_address)
[{'integer': 100}, {'address': '...'}, {'data': ''}]

Get contract program action

control_program_action() - Get contract program action.

Parameter

amount (int) - Bytom amount, [required].
asset (str) - Bytom asset, [required].
control_program (str) - Bytom control program., [required].

Return

action (dict) - Bytom control program action.

>>> from pybytom.transaction.tools import control_program_action
>>> control_program_action(100, "41536cf298d6f261c0a1ac169a45be47583f7240115c9059cd0d03e4d4fab70a", bytom_control_program)
{'type': 'control_program', 'amount': 100, 'asset': '41536cf298d6f261c0a1ac169a45be47583f7240115c9059cd0d03e4d4fab70a', 'control_program': '...'}

Get contract address action

control_address_action() - Get contract address action.

Parameter

amount (int) - Bytom amount, [required].
asset (str) - Bytom asset, [required].
address (str) - Bytom address, [required].

Return

action (dict) - Bytom control address action.

>>> from pybytom.transaction.tools import control_address_action
>>> control_address_action(10000000, "41536cf298d6f261c0a1ac169a45be47583f7240115c9059cd0d03e4d4fab70a", "bm1qzx7pjr6whcaxmh9u0thkjuavf2ynk3zkgshhle")
{'type': 'control_address', 'amount': 10000000, 'asset': '41536cf298d6f261c0a1ac169a45be47583f7240115c9059cd0d03e4d4fab70a', 'address': 'bm1qzx7pjr6whcaxmh9u0thkjuavf2ynk3zkgshhle'}