I am trying to save metadata on Cardano using Blockfrost API, but I keep getting 400 error:
{
"error": "Bad Request",
"message": '"transaction read error RawCborDecodeError [DecoderErrorDeserialiseFailure \\"Byron Tx\\" (DeserialiseFailure 0 \\"expected list len\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 0 \\"expected list len or indef\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 0 \\"expected list len or indef\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 0 \\"expected list len or indef\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 0 \\"expected list len or indef\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 0 \\"expected list len or indef\\")]"',
"status_code": 400,
}
***.
However, I see that the transaction does submit on the blockfrost dashboard; I cannot figure out what I am missing.
def frost_post(data_id, data):
# Construct the payload for creating the transaction with metadata
payload = {
# "outputs": [
# {
# "address": receiving_address,
# # "amount": [{"unit": "lovelace", "quantity": 100000 }],
# }
# ],
"metadata": {data_id: {data_id: data}},
}
# testnet endpoint for creating a transaction with metadata
url = "https://cardano-preprod.blockfrost.io/api/v0/tx/submit"
# Headers including the API key
headers = {
"project_id": config('CARDANO_PROJECT_ID'),
"Content-Type": "application/cbor",
}
# Make the POST request to create the transaction
response = requests.post(url, headers=headers, data=cbor2.dumps(payload))
# check if transaction is successful
if response.status_code == 200:
print("Transaction created successfully.")
else:
print(f"Transaction creation failed. Status code: {response.status_code}")
# return response
return response