An open API service indexing awesome lists of open source software.

https://github.com/primaryobjects/cardanomsg

Store and retrieve text or JSON in the Cardano blockchain metadata.
https://github.com/primaryobjects/cardanomsg

ada bitcoin blockchain cardano crypto metadata pypi pypi-package python transaction

Last synced: 8 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# cardanomsg

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

## Installation

You can install the module using pip:

```sh
pip install cardanomsg
```

## Usage

A [BlockFrost](https://blockfrost.io/) API account is required *(to prevent needing to run the blockchain locally on your PC)*.

## Send message

Send a message in a transaction.

```python
from cardanomsg.transaction import send_message
transaction_hash = send_message("", "wallet.skey", "", 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("", "wallet.skey", "", 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.

```python
from cardanomsg.transaction import get_message
message = get_message("", "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.

```python
from cardanomsg.transaction import find_message
messages = find_message(, 1782959986)
for message in messages:
print(message.json_metadata)
```

*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.

```json
{
"type": "PaymentSigningKeyShelley_ed25519",
"description": "Payment Signing Key",
"cborHex": ""
}
```

## Publishing to PyPi

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

1. Update the version number in [pyproject.toml](https://github.com/primaryobjects/cardanomsg/blob/main/pyproject.toml#L7) and [setup.py](https://github.com/primaryobjects/cardanomsg/blob/main/setup.py#L7).
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