Obi
January 9, 2023, 4:52pm
1
I tried to manually build and submit a transaction to the node but got this error {'message': 'Not Found'}
.
code for reference
import base64
import requests
from algosdk.encoding import msgpack_encode
from algosdk.future.transaction import PaymentTxn, SuggestedParams
from algosdk.util import algos_to_microalgos
key0 = "wf6MGq9+IOzzOKpVIGjZiwaHsEA51FFqM3vt8TRdNVJUEZ23cYux3hBE+2MhrLFN4ezLa1osSa9YT63j1bP5zg=="
acc0 = "KQIZ3N3RROY54ECE7NRSDLFRJXQ6ZS3LLIWETL2YJ6W6HVNT7HHIW35NGE"
acc1 = "EFK7G6BMJTQYNPHUAEWGYMMUDJLDDML2F3UI2LSOUCTGQKZT5L5NMG2AHA"
d = requests.get("https://node.testnet.algoexplorerapi.io/v2/transactions/params")
f = d.json()
params = SuggestedParams(
f["fee"],
f["last-round"],
f["last-round"] + 1000,
f["genesis-hash"],
f["genesis-id"],
False,
f["consensus-version"],
f["min-fee"],
)
txn = PaymentTxn(acc0, params, acc1, algos_to_microalgos(1), note="")
stxn = txn.sign(key0)
encoded = base64.b64decode(msgpack_encode(stxn))
header = {"Content-Type": "application/x-binary"}
send = requests.post(f"https://node.testnet.algoexplorerapi.io/v2/transactions/{encoded}", headers=header)
print(send.json())
thanks
One issue is the following:
You need to post the transactions to the endpoint https://node.testnet.algoexplorerapi.io/v2/transactions as the body of the POST.
Not include the transactions in the URL, as the code
send = requests.post(f"https://node.testnet.algoexplorerapi.io/v2/transactions/{encoded}", headers=header)
does.
In general, we strongly recommend using the SDK to send the requests, rather than manually doing it. You can find a full example there: Your First Transaction - Algorand Developer Portal
If you cannot use the SDK, please let us know why and also please indicate which “requests” JS library you are using.
Obi
January 10, 2023, 5:01am
3
Hello Fabrice, Happy New Year. I was reworking the backend code for Mint Engine and we are trying to do away with the need for x-api-keys (hope this isn’t a bad thing).
I am using the python requests lib pip install requests
.
Thanks for your feedback, I’ve fixed the error.
1 Like
This is ok not requiring them depending on your use case.
However, the SDK does not require them either.
See for example:
from algosdk.v2client import algod
algod_address = "https://node.testnet.algoexplorerapi.io"
algod_token = ""
algod_client = algod.AlgodClient(algod_token, algod_address)
print(algod_client.status())
Obi
January 10, 2023, 7:20pm
5
I didn’t know this🤦. Thanks, thanks alot🙇
Obi
January 11, 2023, 6:04am
6
but the documentation used purestake api, which is why I thought it was enforced by the sdk