Skip to main content

Python SDK for Bitcoin Cash (BCH) CashScript smart contracts.

Project description

CashScript-Py

CashScript-Py is a Python SDK for Bitcoin Cash (BCH) smart contract development. It is a port of the original TypeScript CashScript SDK. The goal is to enable Python developers (e.g., those working on server-side tools, bots, and Electron Cash plugins) to construct and interact with smart contracts on the BCH blockchain without re-implementing common low-level details.

CashScript-Py builds on earlier work by Jonald Fyookball on the anyhedge-ec-plugin.

Installation

Install from PyPI:

pip install cashscript-py

Or, with uv:

uv add cashscript-py

Example

from cashscript_py import Contract, ElectrumNetworkProvider, Output, SignatureTemplate, TransactionBuilder
from .artifact import p2pkh_artifact
from .somewhere import contract_arguments, alice_wif, send_amount, recipient_address

provider = ElectrumNetworkProvider("chipnet")
contract = Contract(p2pkh_artifact, contract_arguments, provider)

alice_signature_template = SignatureTemplate(alice_wif)
unlocker = contract.unlock["transfer"](alice_signature_template)

contract_utxos = await contract.get_utxos()
contract_utxo = contract_utxos[0]

transaction_builder = TransactionBuilder(provider)
transaction_builder.add_input(contract_utxo, unlocker)
transaction_builder.add_output(Output(amount=send_amount, to=recipient_address))

tx_details = await transaction_builder.send()

Documentation

Contributing

For local development setup, testing, documentation generation, and project workflow details, see:

Acknowledgements

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

cashscript_py-1.0.3.tar.gz (36.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cashscript_py-1.0.3-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file cashscript_py-1.0.3.tar.gz.

File metadata

  • Download URL: cashscript_py-1.0.3.tar.gz
  • Upload date:
  • Size: 36.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cashscript_py-1.0.3.tar.gz
Algorithm Hash digest
SHA256 cee26b372d2a4c12112c04ae3bf30ed9a309f962616e5a8ff8b8bef3a3778543
MD5 db7d854ac2927364e248a08bfebb4745
BLAKE2b-256 d27b1259de5162858d68ab3a6c2107eb20ed1778934a8526effc19e3122d4138

See more details on using hashes here.

File details

Details for the file cashscript_py-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: cashscript_py-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 37.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cashscript_py-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3fd2f2be7f5e99038e682091cd0dc09a970159b0fac4efbfb38cf0b2ef545592
MD5 5b3e8330e491dcf2b15933998ce9793a
BLAKE2b-256 9491f1878fd9a711812ac9b01407f3f2c1fc36f802a9a0c717e635958bc53bcf

See more details on using hashes here.

Supported by

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