Using the REST API - General - Algorand

Using the REST API

post by Dave on Nov 7, 2019

Hi all,

Is it possible to make REST API calls without having a local node [fully synced] on my machine?

In other words, would it be possible to get the same functionality of the Algorand block explorer for my python app, but without the need to depend on a local node; which I fear may become an issue in regards to taking up too much space.

Thanks!

post by visybl on Nov 7, 2019

Dave, yes. Just sign up and use purestake api. https://www.purestake.com/technology/algorand-api/

post by pipaman on Nov 7, 2019

Hi Dave,

AlgoExplorer has a full API. We will release it publicly very soon but if you want to start playing with it you can get full documentation here:

https://api.algoexplorer.io/v1/doc/swagger.yml, you can open this file with https://editor.swagger.io/ to read it fully formatted.

Get 10 latest transactions of Binance hot wallet:

https://api.algoexplorer.io/v1/account/SP745JJR4KPRQEXJZHVIEN736LYTL2T2DFMG3OIIFJBV66K73PHNMDCZVM/transactions/latest/10

Get transactions of block 2783757:

https://api.algoexplorer.io/v1/block/2783757/transactions

Get block count on Testnet:

https://api.testnet.algoexplorer.io/v1/block/count

It supports Mainnet / Testnet / Betanet.

Best,

Pablo

post by NHamilton on Nov 11, 2019

Hey Dave - Sorry for the delay here. As Visybl said, you can just sign up for an account on PureStake.com We’ve got a few different levels depending on what you’re looking for. Feel free to reach out if you need a hand nateATpurestakeDOTcom

post by Maugli on Nov 12, 2019

Hi, @NHamilton!

How can the PureStake POST API be used?

Namely, in what binary format should be the transaction?

After using base 64 encoding, the result is:

Error: Bad Request

can't parse JSON. Raw result: msgpack decode error [pos 1]: only encoded map or array can be decoded into a struct

Can you give a specific example of using the POST API?

post by Tim on Nov 12, 2019

At present time, the POST transaction requires an additional header containing the content-type of application/x-binary and in JavaScript in particular one client for the GETs and one for the POST.

PureStake is working with Algorand to try to bake the header directly into the SDK’s for this call and barring that a simplified version where only a single client is created - but for now here is a complete example at https://github.com/PureStake/api-examples/blob/master/javascript-examples/submit_tx.js

PureStake has examples in all the SDK supported languages here - https://github.com/PureStake/api-examples

post by Maugli on Nov 20, 2019

Using PureStake API with cURL, post signed transaction (on Testnet):

$ curl -X POST "https://testnet-algorand.api.purestake.io/ps1/v1/transactions" -H  "accept: application/json" -H  "Content-Type: application/x-binary" -H  "x-api-key: (api_key)" --data-binary @tx1.tx
{"txId":"BLNQO3NTHPW3GPXHGI3P7OXDFJED2PJ4J6XVZAZJ7T5ITCXDWHFQ"}

post by NHamilton on Nov 20, 2019

Great to see. Let us know if you need a hand with anything.

post by wgarcia on May 17, 2020

Hello Maugli, can you please show me what’s inside of the tx1.tx file? I am trying to run the same curl you posted but I am always getting this error message:

msgpack decode error [pos 1]: only encoded map or array can be decoded into a struct

Thanks

post by fabrice on May 18, 2020

Did you try to generate the transaction following this tutorial?

https://developer.algorand.org/docs/build-apps/hello_world/

post by Tim on May 18, 2020

How are you generating the file? From the developer site, creating and signing using goal looks like:

$ goal clerk send --from=<my-account> --to=GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A --fee=1000 --amount=1000000 --note="Hello World" --out="hello-world.txn"

$ goal clerk sign --infile="hello-world.txn" --outfile="hello-world.stxn"

post by fabrice on Nov 16, 2021

Firstly, it’s highly recommended to use the SDK ( algosdk) instead of manually making REST queries. The SDK takes care of all encoding issues.

Code Example

const algosdk = require('algosdk');

(async function() {
    const algodToken = '';
    const algodServer = 'https://testnet.algoexplorerapi.io';
    const algodPort = '';
    const algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);
    
    const status = await algodClient.status().do();
    
    console.log(JSON.stringify(status, null, 2));
})();