发布于 2025-02-10 07:03:16 字数 1319 浏览 2 评论 0原文

在我的情况下,我正在尝试将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 : enter image description here
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黎歌 2025-02-17 07:03:16

津贴方法不是进口资金。津贴功能使用两个地址,第一个是所有者地址,第二个是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.

凶凌 2025-02-17 07:03:16

如果要将令牌导入到MetAmask,请选择该帐户,然后会看到导入令牌选项:

“在此处输入映像”

获取erc20它去了领域。它将自动填充“符号”字段:

”在此处输入图像描述“

单击“添加自定义令牌”,然后您将获得下一个屏幕:

“在此处输入图像说明”

单击“ import tokens”

If you want to import token to metamask, choose the account and you will see the import token option:

enter image description here

Get the ERC20 token address and paste it to the field. It will automatically populate the "symbol" field:

enter image description here

Click on "Add Custom Token" then you will get next screen:

enter image description here

click on "Import Tokens"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文