Metamask stopped using web3. Their own API has no methods for interacting with ERC20, ERC721 contracts. How do I accomplish simple task of reading token balance for a wallet on an ERC721 contract?
1 Answer
Look at eth_call
on Metamask API Docs.
Here is an example query for retrieving ERC20 balance:
{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"data": "0x70a0823100000000000000000000000028c6c06298d514db089934071355e5743bf21d60",
"to": "0xdac17f958d2ee523a2206206994597c13d831ec7"
},
"latest"
],
"id": 0
}
to
is the contract address (in this case - USDT)
data
consists of:
- the first 4 bytes of
keccak256(balanceOf(address))
(function hash) - the wallet address that you want to retrieve balance for (in this example -
0x28c6c06298d514db089934071355e5743bf21d60
).
The same should work for NFTs since ERC721 balanceOf matches ERC20 specs.
Metamask stopped using web3.
This is not true.