Skip to main content

A module to send Cardano ADA with a message in the metadata.

Project description

cardanomsg

Store and retrieve text or JSON in the Cardano blockchain metadata.

Installation

You can install the module using pip:

pip install cardanomsg

Usage

A BlockFrost API account is required (to prevent needing to run the blockchain locally on your PC).

Send message

Send a message in a transaction.

from cardanomsg.transaction import send_message
transaction_hash = send_message("<BLOCKFROST_PROJECT_ID>", "wallet.skey", "<RECIPIENT_ADDRESS>", 1000000, "Hello World")

Send message with label

Send a message with a searchable label in a transaction.

label = uuid.uuid4().int & (1<<32)-1
payload = {
    "id": 12345,
    "text": "Hello World"
}
transaction_hash = send_message("<BLOCKFROST_PROJECT_ID>", "wallet.skey", "<RECIPIENT_ADDRESS>", 1000000, payload, label)

The label must be numeric. Wait 1-3 minutes after submitting the transaction to find your label.

Get message

Get a message from a transaction.

from cardanomsg.transaction import get_message
message = get_message("<BLOCKFROST_PROJECT_ID>", "079112f6a5192c6eeae57de0607d61e07dea864efc2bbad7aa953795a5c56aae")[0].json_metadata

You can also view the message on the blockchain using Cardanoscan.

https://preview.cardanoscan.io/transaction/079112f6a5192c6eeae57de0607d61e07dea864efc2bbad7aa953795a5c56aae?tab=metadata

Summary | UTXOs | Metadata (1)

Metadata Hash: 2f86fa9fdfcb606ab2b5f060bd125848e45187cf2c798ab389e6a9af98ba8ad1
Public Label: 1
Value: "Hello World"

Find message

Find messages using a label.

from cardanomsg.transaction import find_message
messages = find_message(<BLOCKFROST_PROJECT_ID>, 1782959986)
for message in messages:
    print(message.json_metadata)

Find messages using a label on Cardano mainnet, count 10, page 2, sorted by most recent.

from blockfrost import ApiUrls
messages = find_message(<BLOCKFROST_PROJECT_ID>, 123, api=ApiUrls.mainnet, count=10, page=2, order='desc')

The label must be numeric.

Create wallet

Create a wallet.

from cardanomsg.wallet import create
result = create()

Two files will be created: wallet.skey and wallet.addr.

The contents of wallet.skey is the secret key with the following format.

{
  "type": "PaymentSigningKeyShelley_ed25519",
  "description": "Payment Signing Key",
  "cborHex": "<SENDER_SECRET_KEY>"
}

Publishing to PyPi

Use the following steps to publish a new version to PyPi.

  1. Update the version number in pyproject.toml and setup.py.
  2. Package the distributable: py -m build
  3. Upload the package: py -m twine upload dist/*
  4. Confirm the new version at https://pypi.org/project/cardanomsg

License

MIT

Author

Kory Becker http://primaryobjects.com

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

cardanomsg-0.1.5.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

cardanomsg-0.1.5-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file cardanomsg-0.1.5.tar.gz.

File metadata

  • Download URL: cardanomsg-0.1.5.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for cardanomsg-0.1.5.tar.gz
Algorithm Hash digest
SHA256 7fe38dccbdcad9fdba915ff385b2af0c9229400a8f8c8d11105f314b017f62ef
MD5 8f16cc5f197c6c316015dd522ab97787
BLAKE2b-256 1d4061eeed2ceb56fab57452c7095a0676f157a3d695a4a5de8836aee5d39444

See more details on using hashes here.

File details

Details for the file cardanomsg-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: cardanomsg-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for cardanomsg-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 91ff69a6dbfc13a11d5abc2814204f146707648fccfc2aaa93c33d4ce2b1c915
MD5 ca9f08018690d27cffac958ea1dca7a3
BLAKE2b-256 15c4c5fb96fc8f5b3e7cb44b93cad0c366840b90a2a36f5521c2e953a4eaae76

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