[英]How do I check if a proton chain user exists properly and reliably from the front-end?
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 ) 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.谢谢。
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;
} }
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);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.