-1

If I go to https://protonscan.io/accounts/username I get a 400 response for a user that doesn't exist and a 200 response for a user that exists on get_account (https://proton.greymass.com/v1/chain/get_account)

How do we check this properly and reliably and "Nice to have": How do we get the avatar for that user or other information, all from the front end?

Thanks.

1

2 Answers 2

0

So the solution I chose is this:

let userProvided; // here I get the username from the front-end
// then I fetch the user's data
fetch('https://proton.eosusa.news/v2/state/get_account?account=' + userProvided).then(response => {
  return response.json();
}).then(data => {
// after the data is parsed into an object we can use it here
   console.log(data);
});
1
0

I use that code on the backend (TypeScript).

async isAccountExist(newAccountName: string): Promise<boolean> {
    const rpc = new ProtonRPC();
    const account = await rpc.getAccount(newAccountName);
    if (account) 
        return true;
    return false;
}
4
  • Can be shorter by returning !!account
    – RockerOne
    Commented Sep 5, 2022 at 7:51
  • There is a gist here gist.github.com/SuperstrongBE/…
    – RockerOne
    Commented Sep 5, 2022 at 7:53
  • That's very nice, but at the moment I am trying to solve it on the front-end so the server doesn't have to work for this bit.
    – Lucian
    Commented Sep 5, 2022 at 8:04
  • This works from front end too But for pure rest API, you could use axios / fetch response code, or a good old try catch
    – RockerOne
    Commented Sep 5, 2022 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.