Skip to main content

Binance Chain Transactions

Project description

Binance Chain Transaction Library

This library provides a low-level interface for interacting with different Binance Chain transactions.

Installation

pip3 install bnb-tx

Or, in your Pipfile:

bnb-tx = "==0.0.4"

Usage

The following is an example that uses the ecdsa library to sign.

import ecdsa
def uncompressed_public_key(sk):
    """ Derive uncompressed public key """
    order = sk.curve.generator.order()
    p = sk.verifying_key.pubkey.point
    x_str = ecdsa.util.number_to_string(p.x(), order)
    y_str = ecdsa.util.number_to_string(p.y(), order)
    uncompressed = b'\x04' + x_str + y_str
    return uncompressed


from binance_transaction import BnbTransaction, NewOrder, address_bytes, BUY, GTE, LIMIT_ORDER

sk = ecdsa.SigningKey.from_pem(open('secp256k1-key.pem').read())
from_address = 'bnb100dxzy02a6k7vysc5g4kk4fqamr7jhjg4m83l0'
account_number = 96025  # https://docs.binance.org/api-reference/dex-api/paths.html#apiv1accountaddress
sequence_number = 888
tx = BnbTransaction(account_number, sequence_number)
order_id = f'{address_bytes(from_address).hex().upper()}-{sequence_number + 1}'
tx.add_msg(NewOrder(from_address, order_id, 'BNB_TUSDB-888', LIMIT_ORDER, BUY, 3500000000, 500000000, GTE))
print(tx.signing_json())
sig = sk.sign_digest(tx.signing_hash())
public_key = uncompressed_public_key(sk)
tx.apply_sig(sig, public_key)
signed_transaction_bytes = tx.encode()
print(f'Signed bytes: {signed_transaction_bytes.hex()}')

Support

Not all transaction types are supported. Please consult this table for details. If you need support, please submit a pull request.

Message Type encode decode from_obj
Send
NewOrder
CancelOrder
Issue
Mint
Burn
Freeze
Unfreeze
TimeLock
TimeUnlock
TimeRelock
Proposal
Vote

Contributing

See CONTRIBUTING.

License

LGPLv3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bnb-tx-0.0.4.tar.gz (11.8 kB view details)

Uploaded Source

File details

Details for the file bnb-tx-0.0.4.tar.gz.

File metadata

  • Download URL: bnb-tx-0.0.4.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for bnb-tx-0.0.4.tar.gz
Algorithm Hash digest
SHA256 eec6a746e0f30ccab21a6c222f8aad0a9eb64c519b65a650a0415fdbc90625fc
MD5 f4a3bc52654fc3defd3aa1e371545317
BLAKE2b-256 198c1805c2cbafea27de316cab112103c1838a7064b952c7dd09b595c84fd7f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page