Metamask: Hardhat & Metamask not showing imported custom token
Here is an article based on your contribution:
Error with the optional token balance Metamque
Recently, I installed an optional ERC20 token using firmness on my local computer and established the random distribution of 10 accounts that I imported for the purposes of the hardhat test. As part of the installation process, I configured Metamk to import all these accounts.
At first it seemed that everything worked as expected. I could call the balance agreement under the intelligent contract implemented and obtain precise results. However, when I was trying to achieve the balance of a specific account, I began to receive an error message using the same Balantof function.
After a certain study, I discovered that the problem is not my installation or hardhat configuration, but with the MetamSk itself. Specifically, the “imported custom chip function” does not seem to be expected when used with an intelligent contract implemented.
Question: Optional Imported Token
According to several online forums and community discussions, I was able to replicate the problem by importing my 10 accounts in MetamSk using the “importer” function. When I imported these accounts to Metamkk, I noticed that they were not really used as a parked contract.
The Balantof function awaits the address or arrows of a specific contract balance account, but since my accounts have imported without specifying what use, it did not work properly. To solve this problem, I needed to specify the correct account address using the “importer” function presented by the Metamkk.
To solve the problem
To solve this problem, I followed the following steps:
- Create a new file called Item.js in the same catalog as my contract and install the contract code.
- Use this line of code in this importer scenario to import specific accounts to MetamSk:
`JavaScript
Const accounts = waiting for window.ethereum.send ("importers", {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
Accounts: [
{Name: account1},
{Name: account2},
// ... add more accounts if necessary ...
]
});
This will import the specified invoices to Metamkk and determine them as the current account of our contract.
- Update the installation code of my contract to use this importer scenario instead of importing all accounts with a Balantof call:
JavaScript
Pragma solidity ^0.8.0;
Contract based on customization {
// ...
}
Importer (direction _importora) payable for importers._accouns;
Functions Balance () Public Video Return (Uint256) {
Uint256 balance = _importer.balanceof (_contractaddress);
Return balance;
}
`
When taking these steps, I could solve the problem when I imported custom chips to MetamSk and access their waste under my parked contract.