CareBoo / unity-algorand-sdk

An Algorand SDK for Unity. Use the Algorand blockchain in your video game.
MIT License
31 stars 15 forks source link

How to use Purestake algorand api as AlgodClient #58

Closed emaadgh closed 3 years ago

emaadgh commented 3 years ago

Hi, I want to use Purestake Algorand API as my node in the Algorand blockchain and not set one up by myself. To be able to connect to Purestake API, I need the ALGOD V3.0.1 TESTNET address :

https://testnet-algorand.api.purestake.io/ps2

and a private API key that is prepared in the Purestake panel.

I tried the following code from quickstart with Purestake like :

algod = new AlgodClient( address: "testnet-algorand.api.purestake.io/ps2", token: "my private API key" );

and CheckAlgodStatus prints out :

Connected to algod!

but when I use CheckBalance() function to check my wallet on the Algorand test net, it always returns

My account has 0 algos

and it seems not working properly cause I have algos in my TestNet wallet address that I'm using in CheckBalance().

Have you tried to test this plugin with Purestake API? am I missing something?

Regards.

jasonboukheir commented 3 years ago

I haven't tried purestake myself, I see now that they have specific headers.

There are 2 issues here:

The token given in the AlgodClient constructor is used with the X-Algo-API-Token header key, while purestake is using x-api-token (and no X-Algo-API-Token) to authenticate its apis.

jasonboukheir commented 3 years ago

I should have a fix in soon @emaadgh :) and thanks for reporting these issues!

Currently updating the integration tests so I can change the AlgodClient, IndexerClient, and KmdClient settings from environment vars or inside the editor. This should let me easily test the clients against different nodes.

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.2.0-pre.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

jasonboukheir commented 3 years ago

@emaadgh I went ahead and updated the docs too on how to customize the http headers. For purestake, you're going to wanna do something like

algod = new AlgodClient(
   "https://testnet-algorand.api.purestake.io/ps2/v2/status",
   ("x-api-key", "my-super-secret-api-key")
);
github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.2.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

emaadgh commented 3 years ago

@emaadgh I went ahead and updated the docs too on how to customize the http headers. For purestake, you're going to wanna do something like

algod = new AlgodClient(
   "https://testnet-algorand.api.purestake.io/ps2/v2/status",
   ("x-api-key", "my-super-secret-api-key")
);

Thanks, Jason, I've tested the new version with this custom header but I'm getting

Missing Authentication Token

from response of await algod.GetHealth(); .

I like to mention that the curl command is working with a schema like this in Command-Line with the same token :

curl -X GET "https://testnet-algorand.api.purestake.io/ps2/v2/status" -H "x-api-key:secret-token"

jasonboukheir commented 3 years ago

Hi @emaadgh ,

Sorry I had a typo in my URL. You want to use the root of the algod service:

https://testnet-algorand.api.purestake.io/ps2