cardanomsg
0.1.3
จัดเก็บและดึงข้อความหรือ JSON ในข้อมูลเมตาของ Cardano blockchain
คุณสามารถติดตั้งโมดูลโดยใช้ PIP:
pip install cardanomsgจำเป็นต้องมีบัญชี blockfrost API (เพื่อป้องกันไม่ให้เรียกใช้ blockchain ในเครื่องพีซีของคุณ)
ส่งข้อความในธุรกรรม
from cardanomsg . transaction import send_message
transaction_hash = send_message ( "<BLOCKFROST_PROJECT_ID>" , "wallet.skey" , "<RECIPIENT_ADDRESS>" , 1000000 , "Hello World" )ส่งข้อความพร้อมฉลากที่ค้นหาได้ในธุรกรรม
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)
ฉลากต้องเป็นตัวเลข รอ 1-3 นาทีหลังจากส่งธุรกรรมเพื่อค้นหาฉลากของคุณ
รับข้อความจากธุรกรรม
from cardanomsg . transaction import get_message
message = get_message ( "<BLOCKFROST_PROJECT_ID>" , "079112f6a5192c6eeae57de0607d61e07dea864efc2bbad7aa953795a5c56aae" )[ 0 ]. json_metadataคุณยังสามารถดูข้อความบน blockchain โดยใช้ cardanoscan
https://preview.cardanoscan.io/transaction/079112f6a5192c6eeae57de0607d61e07dea864efc2bbad7aa953795a5c56aae?tab=metadata
Summary | UTXOs | Metadata (1)
Metadata Hash: 2f86fa9fdfcb606ab2b5f060bd125848e45187cf2c798ab389e6a9af98ba8ad1
Public Label: 1
Value: "Hello World"
ค้นหาข้อความโดยใช้ป้ายกำกับ
from cardanomsg . transaction import find_message
messages = find_message ( < BLOCKFROST_PROJECT_ID > , 1782959986 )
for message in messages :
print ( message . json_metadata )ฉลากต้องเป็นตัวเลข
สร้างกระเป๋าเงิน
from cardanomsg.wallet import create
result = create()
สองไฟล์จะถูกสร้างขึ้น: wallet.skey และ wallet.addr
เนื้อหาของ wallet.skey เป็นกุญแจลับที่มีรูปแบบต่อไปนี้
{
"type" : " PaymentSigningKeyShelley_ed25519 " ,
"description" : " Payment Signing Key " ,
"cborHex" : " <SENDER_SECRET_KEY> "
}มิกซ์
Kory Becker http://primaryobjects.com