We have a way to add an ERC20 token to the metamask wallet from our dapps with a RPC method:
const addTokenToMetamask = async () => {
if (typeof window.ethereum !== "undefined") {
const tokenAddress = "0x;
const tokenSymbol = "TOKEN";
const tokenDecimals = 18;
const tokenImage =
"https://raw.githubusercontent.com/logo.png";
try {
// wasAdded is a boolean. Like any RPC method, an error may be thrown.
const wasAdded = await window.ethereum.request({
method: "wallet_watchAsset",
params: {
type: "ERC20", // Initially only supports ERC20, but eventually more!
options: {
address: tokenAddress, // The address that the token is at.
symbol: tokenSymbol, // A ticker symbol or shorthand, up to 5 chars.
decimals: tokenDecimals, // The number of decimals in the token
image: tokenImage, // A string url of the token logo
},
},
});
} catch (error) {
console.log(error);
}
}
};
As NFTs can be added from the v10.30 metamask version of the browser, I was wondering if there was any RPC method to add nfts to the metamask from our dapps. If not, how would you do it?