Submitting my transactions to Purestake from GNU/lLinux cli (specifically using curl)

I’m trying to set up my own system of creating transactions, signing offline, and then sending them to the blockchain by way of an API, in this case Purestake. I’m not a professional developer, but have a decent knowledge of Algorand and shell scripting/cli and I want to do this on a GNU/Linux command line and ultimately in my own shell script.

The reason I am trying to do it this way is a) I want to control the process as much as possible and b) I can’t run my own node because the bandwidth usage is prohibitive to me. Unfortunately goal’s transaction creation commands require you to be running a node.

I have already learned how to 1) create the transaction JSON file, 2) convert it to msgpack, 3) sign the transaction using algokey. I have used goal to read the signed transaction file in JSON format and it looks good to go.

I already have a Purestake account with my own API key. However, I’m not a professional developer, so the Purestake documentation on the site is rather cryptic to me. In any case it is written for people using one of the Algorand SDKs with Java, Javascript, Python, etc.

So all I need to be able to do now is to send transactions to Purestake using the curl command. I understand that the command will be something like “curl -X POST …” but don’t know how to format it properly to get it done. Could someone here kindly tell me how I would send my transaction to Purestake’s API using curl?

Thanks very much in advance!

If you have the base64 msgpack data blob you need to convert it to binary as the api accepts application/x-binary. This step can be done with the following command to save the binary data to a file:
base64 -d <<< MSGPACK_DATA > signed.tx

Then you can make the call to the PureStake api using the following after swapping in your api key:
curl -X POST 'https://testnet-algorand.api.purestake.run/ps2/v2/transactions' --header 'x-api-key: API_KEY' --header 'content-type: application/x-binary' --data-binary '@signed.tx'

1 Like

Thanks very much for this very helpful response! I will try it shortly on testnet before making an attempt on the mainnet.

The command line utility for msgpack that I’m using seems to render everything in binary (I checked the file using xxd, and goal can inspect it and gets JSON data out of it correctly). So I think that part is ok.

I’m wondering also if I can sign these without algokey. I assume that the transaction is signed by taking a hash, signing that, and then including the signed hash in the msgpack as one of the fields (as I can see it displays after signing when I run “goal clerk inspect” on the signed file). Can that be done “manually” on the command line as well?

Thanks again!

You will need in anyway to generate the msgpack data properly, which requires an external tooling (such as msgpacktool from Algorand).
Why don’t you want to use algokey or goal clerk sign?
You can install these tools without having a node running.

Thanks for your response Fabrice.

I am already generating the msgpack using a utility I downloaded from GitHub - ludocode/msgpack-tools: Command-line tools for converting between MessagePack and JSON / msgpack.org[UNIX Shell]. I tested it by 1) creating the json file 2) converting it to a msgpack file 3) signing it using algokey 4) using goal clerk inspect to convert the signed msgpack into json again. It worked fine.

I am currently using algokey to do the signature offline, and it works fine without a node (and fortunately it is statically linked). I was just wondering if I could do the signature “by hand” to understand the process better. I don’t know how the signature is generated exactly but I assume there is a developer page that explains it (I haven’t seen it yet).

Regarding “goal clerk sign”: I wouldn’t mind using it, and in fact I would also like to be able to use goal to generate the json msgpack file to sign in the first place rather than creating the file by hand, but I have found that I can’t use those functions without a node.

For example, if I just try to do goal clerk sign with the -i [msgpack json file] -o [signed msgpack file] set, I get the following error message:

Data directory not specified. Please use -d or set $ALGORAND_DATA in your environment. Exiting.

If I try to set -d to an arbitrary directory, I get another message mentioning that kmd wasn’t found, etc.

So that’s where I am with that. With what I’ve been given so far I should be able to do the offline key generation and signing without any problem using algokey, but I was just wondering how much of this I could do in my own shell script. The basic reason is that I like to understand and control the process as much as possible.

I believe you should be able to do everything manually using openssl and an msgpack system.
But it will be painful.
You need to prefix the transaction to be signed with some prefix in particular.
You can see the process in Python there:

Indeed, to use goal, you would need an ALGORAND_DATA folder, and you may even need to sync for a few seconds. But then you won’t need it more.

I think that I would do well to learn Python or Go to do this little project but I will try to make do with a couple of shell scripts to begin with. I did look at the code you linked to but I don’t know what all of those functions do. That’s ok though because as long as I can make my own JSON files, convert them to msgpack, sign them offline with algokey, and then send them to the API using curl, it’ll do what I need. Thanks!