Where can I fid the missing auth token for test-net?

I have this function linked to a button

string ALGOD_API_ADDR_TESTNET = "https://testnet-algorand.api.purestake.io/ps2";
            string ALGOD_API_TOKEN_TESTNET = API KEY FOUND in PURESTAKE;
            AlgodApi algodApiInstances = new AlgodApi(ALGOD_API_ADDR_TESTNET, ALGOD_API_TOKEN_TESTNET);
           
            var c = _address.Text;
            try 
            {
                var accountInfo = algodApiInstances.AccountInformation(c.ToString());
                Debug.WriteLine("");
                _balance.Text = $"{accountInfo.Amount}";
                await DisplayAlert("Account Address", $"MicroAlgos: {accountInfo.Amount}", "OK"); 
            } catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

Having done as explicitly said in tutorials and in YouTube video, however, I keep getting the "missing authentication tokenĀ° error.
Also with breakpoint, my AlgodApi algodApiInstances shows nulla as access token.

Thanks in advance.

You could try something such as:

const algod_address = "https://node.algoexplorerapi.io" 
const algod_token = ""

This would allow you to run on Mainnet. For testnet with the Purestake address you are using, you would need to log in to Purestake to find you API Token.

Indeed I signed up and logged and retrieved my API token. I insert it in initialization for the AlgodApi algodApiInstances object. However auth token keeps on being null.

only purestake guys uses the tokens for authentication as far as i knowā€¦ and they use custom header for it ā€¦ x-api-key

From my experience AlgoNode is the best nodes provider: API

If you really want to use pure stake, this is the wayā€¦


const token = 
	{
		'X-API-Key': x_api_key
	};
const server = "https://testnet-algorand.api.purestake.io/ps2";
const serverIdx = "https://testnet-algorand.api.purestake.io/idx2";
const port = "";

// Instantiate the algod wrapper
let algodClient = new algosdk.Algodv2(token, server, port);

Also notice, that you attempted to use AlgodApi instead of newer algosdk.Algodv2

And for the record, the indexer is used to load the account information, not the algod.

What is the algosdk.Algodv2 equivalent in C#?

UPDATE:

I tried this

            var boh = new Configuration();
            boh.AddDefaultHeader("X-API-Key", ALGOD_API_TOKEN_TESTNET);
            boh.AccessToken = ALGOD_API_TOKEN_TESTNET;
            boh.BasePath = ALGOD_API_ADDR_TESTNET;
            IDictionary<string, string> apiKey = new Dictionary<string, string>()
            {
                ["X-API-Key"] = ALGOD_API_TOKEN_TESTNET
            };
            boh.ApiKey = apiKey;
            boh.Password = _wPass; //wallet password
            AlgodApi algodApiInstances = new AlgodApi(ALGOD_API_ADDR_TESTNET, ALGOD_API_TOKEN_TESTNET);
            algodApiInstances.Configuration = boh;

I added configuration object with access token (i used the apiToken) and default header and so on
And still no actual improvement.
Is C# V2 of API actually usable?

In this folder is few examples on how to use itā€¦ dotnet-algorand-sdk/sdk-examples at master Ā· FrankSzendzielarz/dotnet-algorand-sdk Ā· GitHub

Note that the ConfigureHttpClient method dotnet-algorand-sdk/HttpClientConfigurator.cs at 2ec9d2e8db9f1f7a7f2528a598855f0bb848c36e Ā· FrankSzendzielarz/dotnet-algorand-sdk Ā· GitHub has parameter header where you can supply the x-api-key

Also note that AlgodApi is old, and you should use DefaultApi to access the algodā€¦

Also note that there are 2 algorand nuget packages, one from RileyGe and one from Frankā€¦ I recommend to use the one from Frank as there is a lot of new work done, is better to use and is under active developmentā€¦ For example if you use the boxes, it is the only way to go as they were introduce in past year.

Thank you so much for your care and your quick responsesā€¦ However, unluckily, still no improvements.

    var httpClient = 
    HttpClientConfigurator.ConfigureHttpClient(ALGOD_API_ADDR, 
    ALGOD_API_TOKEN);
    DefaultApi algodApiInstance = new DefaultApi(httpClient);

This section, for example, relies on V2 modules (only DefaultApi in V2 requires the httpClient as arg), while this:

    var accountInfo = await 
    algodApiInstance.AccountInformationAsync(srcAccount.Address.ToString(), null, null);

seems to require the previous version.

I changed it in:

     var accountInfo = await algodApiInstance.AccountsAsync(srcAccount.Address.ToString(), null);

adopting the V2 methods, however I still get an error about the http request.

I also tried to ā€œcopy ā€˜nā€™ pasteā€ the whole thing from github, but indeed, again, nothing works.
Maybe I need to perform a downgrade of the NuGet module for Algorandā€¦ But I am close to give up

Try thisā€¦

var accountInfo = await algodApiInstance.AlgodClient.AccountInformationAsync(srcAccount.Address.ToString(), null, null);

Also, @FrankS is active on Discord and very friendly and helpful.

2 Likes

Ping me on the dev discord on NET SDK

In the meantime try the examples Algorand .NET SDK (frankszendzielarz.github.io)

Also try adding trailing slash ā€œ/ā€ on the end of the purestake base URL and let me know if that affects you.

1 Like

Hi, thanks again!
I added the Algorand channel on Discord but (thanks for understanding I am a newbie there) I cannot find your name (FrankS) yet.

Welcome to Algorand!
You need to follow the instructions in the #welcome Discord channel if you have not done so, so you can access all the Discord channels.
This requires in particular solving a CAPTCHA sent by DM.