Bad request error

Hey guys !!!
I’m trying to use the js sdk with purestake.io testnet api but i keep getting a BAD REQUEST error

const algosdk = require(“algosdk”)
const baseServer = ‘https://testnet-algorand.api.purestake.io/idx2
const port = ‘’;
const token = {
‘X-API-Key’: ‘API KEY’
}

const algodclient = new algosdk.Algod(token,baseServer, token)

let account = algosdk.generateAccount();
// console.log(account.addr)
const main = async() => {
try{
// const info = await algodclient.accountInformation(account.addr)
// let acct_string = JSON.stringify(account_info)
console.log(“Account Info:”, algodclient)
}catch(e){
console.log(e.message)
}
}
main()

https://testnet-algorand.api.purestake.io/idx2 is for the Indexer V2 endpoint.

const algodclient = new algosdk.Algod(token,baseServer, token)

creates an Algod V1 client.

You should use instead:

let indexerClient = new algosdk.Indexer(indexer_token, indexer_server, indexer_port); // new

See https://developer.algorand.org/docs/reference/sdks/migration/#client-instantiations

1 Like

thanks @fabrice, i hope purestake can update their docs, its misleading

can i get like a link to the updated docs ??
i have another error already algodclient.accountInformation is not a function
i’m trying to get the balance of an address

See https://developer.algorand.org/docs/features/indexer/ for Indexer V2

Apologies for any confusion - we’ve updated the examples page and added new examples to the api-examples GitHub repo today.

There are also a few new notes about known issues in the v2 APIs and SDK implementations.

The specific call you are looking for in the above (for the JS SDK)
let accountLookup = await indexerClient.lookupAccountByID('ACCOUNT').do() console.log(accountLookup.account.amount)