Metamask: How to send a specific token from a wallet if there are multiple tokens

Sending Specific Tokens from MetaMask: A Step-by-Step Guide

MetaMask is a popular cryptocurrency wallet that allows users to interact with the Ethereum blockchain. In this article, we will show you how to send specific tokens from your Metamask wallet to another wallet programmatically.

Prerequisites

  • You have a MetaMask wallet installed on your computer or mobile device.
  • You have two ERC20 tokens in your Metamask wallet, for example TOKEN_1 and TOKEN_2.
  • The receiving wallet has the necessary permissions to receive tokens.

Step 1: Get the Token Addresses

Metamask: How to send a specific token from a wallet when there are multiple tokens

To send specific tokens from your Metamask wallet, you need to get their addresses. Here’s how to do it:

  • Open MetaMask on your computer or mobile device.
  • Go to the “Wallet” > “Exchange” tab and click on the “Token List” button.
  • Find the two ERC20 tokens you want to send from the list of available tokens.
  • Click on the address of each token in the list. This will open a new tab with the token details, including its contract address.

Step 2: Send Tokens Using RPC

To send specific tokens from your Metamask wallet to another wallet programmatically, you need to use Web3’s Remote Procedure Call (RPC) feature. Here’s how to do it:

  • Make sure you have a MetaMask extension installed on your browser.
  • Go back to the “Token List” tab in MetaMask and select the two tokens you want to send.
  • Click the “Send” button next to each token. This will open a new window with the recipient’s wallet details.

Step 3: Enter Recipient Wallet Information

In the “Send” window, enter the following information for the recipient wallet:

  • Contract Address
  • Private Key (or Account Address)
  • Gas ​​Limit (optional)

Step 4: Confirm Token Sending

Once the necessary information is entered, click the “Confirm” button to send the tokens.

Sample Code

Here is a sample JavaScript snippet that shows how to send specific tokens from your Metamask wallet to another wallet:

const MetaMask = require('metamask');

// Replace with your own private key and contract address

const privateKey = '0x...';

const recipientContractAddress = '0x...';

const metaMask = new MetaMask({

extension: true,

accounts: [privateKey],

});

metaMask.on('connect', () => {

const tokenAddresses = ['0x...', '0x...'];

tokenAddresses.forEach((tokenAddress) => {

// Send TOKEN_1 to recipient's wallet

metaMask.send({ to: recipientContractAddress, tokens: [tokenAddress] });

});

});

metaMask.on('connect', () => {

const tokenAddresses = ['0x...', '0x...'];

tokenAddresses.forEach((tokenAddress) => {

// Send TOKEN_2 to the recipient's wallet

metaMask.send({ to: recipientContractAddress, tokens: [tokenAddress] });

});

});

This code snippet shows how to send specific tokens from your MetaMask wallet to another wallet using RPC. You will need to replace privateKey and recipientContractAddress with your own private key and contract address.

Conclusion

Sending specific tokens from MetaMask is a simple process that requires minimal setup. By following the steps outlined in this article, you can easily send ERC20 tokens between wallets programmatically using Web3’s RPC functionality. Happy coding!