Home > front end >  How do I check if a proton chain user exists properly and reliably from the front-end?
How do I check if a proton chain user exists properly and reliably from the front-end?

Time:09-06

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.

CodePudding user response:

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);
});

CodePudding user response:

I personally use that code on backend (typscript).

   async isAccountExist(newAccountName: string): Promise<boolean> {
   const rpc = new ProtonRPC();
   const account = await rpc.getAccount(newAccountName);
   if (account) 
      return true;
   return false;
}
  • Related