。
在我的情况下,我正在尝试将ERC20令牌导入MetAmask中的ERC20令牌的方法。 问题是我没有因导入ERC20令牌而获得MetAmask弹出窗口,但是我在没有导入的情况下获得了特定帐户的余额PKS令牌。
在获取平衡之前需要此输出: 有什么方法可以调整应该首先要求导入的代码,然后取得余额。
到目前为止,这是我的代码,我正在使用使用效果的GeterCbal:
async function getErcBal(){
var WEB3 = await connection();
var currAddr = WEB3.address;
var web3 = WEB3.web3Conn;
if(WEB3.isMeta){
setuseraddress(currAddr);
setContractAdr(dethContractAddr);
if(dethContractAddr){
var dethContract = new web3.eth.Contract(DETH, dethContractAddr);
var getAllowance = await dethContract.methods
.allowance(currAddr, dethContractAddr)
.call();
}
var tokenDethBln = await dethContract.methods.balanceOf(currAddr).call();
}
var PksVal = 0;
if (tokenDethBln && tokenDethBln > 0) {
PksVal = tokenDethBln / 1000000000000000000;
}
setPksbalance(PksVal.toFixed(4))
}
}
I was trying out the .allowance method to import erc20 token in my case PKS to metamask.
The issue is I don't get the metamask popup for importing the erc20 token but I get the balances PKS token for the particular account without importing .
need this output before fetching balances :
Is there any way to adjust the code it should first ask for import and then fetch the balance.
here's my code so far and I am calling getErcBal in useEffect :
async function getErcBal(){
var WEB3 = await connection();
var currAddr = WEB3.address;
var web3 = WEB3.web3Conn;
if(WEB3.isMeta){
setuseraddress(currAddr);
setContractAdr(dethContractAddr);
if(dethContractAddr){
var dethContract = new web3.eth.Contract(DETH, dethContractAddr);
var getAllowance = await dethContract.methods
.allowance(currAddr, dethContractAddr)
.call();
}
var tokenDethBln = await dethContract.methods.balanceOf(currAddr).call();
}
var PksVal = 0;
if (tokenDethBln && tokenDethBln > 0) {
PksVal = tokenDethBln / 1000000000000000000;
}
setPksbalance(PksVal.toFixed(4))
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
津贴方法不是进口资金。津贴功能使用两个地址,第一个是所有者地址,第二个是Spender地址。如果您以前批准某人使用您的资金,那么它将返回一些价值,否则将给出零。
Allowance method is not for importing funds. Allowance function uses two addresses, first one is owner address, and second one is spender address. If you previously approved someone to use your funds then it will return some value, otherwise it will give zero.
如果要将令牌导入到MetAmask,请选择该帐户,然后会看到
导入令牌
选项:获取
erc20
它去了领域。它将自动填充“符号”字段:单击“添加自定义令牌”,然后您将获得下一个屏幕:
单击“ import tokens”
If you want to import token to metamask, choose the account and you will see the
import token
option:Get the
ERC20
token address and paste it to the field. It will automatically populate the "symbol" field:Click on "Add Custom Token" then you will get next screen:
click on "Import Tokens"