Here is an article that will resolve your issue with Metamask custom RPC not sending correct contract information:

Metamask Custom RPC Issue: Fixing Contract Information

When migrating deployments from Truffle to Metamask, it is common to encounter issues related to contract metadata. In this article, we will explore a possible reason why Metamask custom RPC is sending incorrect contract ID and provide steps to resolve the issue.

Problem: Incorrect contract metadata in custom RPC

Metamask: Metamask custom rpc not sending correct contract info

In your Truffle configuration file (truffle-config.js), you are setting the metamaskConfig option with the following code:

`javascript

module.exports = {

// ... other configurations ...

metamaskConfig: {

host: 'localhost:7545',

port: 8545,

networkId: 1, // set to default (mainnet)

publicAddress: '',

rpcUrl: 'ws://localhost:7545', // enter the full RPC URL

},

};

Regarding setting therpcUrloption, you are using the short form version ('ws://localhost:7545'), which is correct. However, when connecting to Metamask, the actual URL sent by the custom RPC will be a long string including the contract ID and network information.


Incorrect contract information in custom RPC



The problem arises because Truffle uses a specific format (e.g. contracts) to send metadata over web3 RPC. When you use a short-form URL ('ws://localhost:7545'), yourrpcUrloption is used instead of the correct full URL.

This is what happens:


  • Short-form URL: You are using a shortened URL, which is fine for Truffle.


  • Full URL: When you connect to Metamask using this short-form URL, it sends metadata over the
    wsprotocol, where the contract IDs are encoded in a specific format.

To fix the issue, make sure to use the correct full URL when setting yourrpcUrloption:

javascript

module.exports = {

// ... other configurations ...

metamaskConfig: {

host: 'localhost:7545',

port: 8545,

networkId: 1, // set to default (mainnet)

publicAddress: '',

rpcUrl: 'ws://localhost:7545/metadata', // correct full URL

},

};

By using the correct full URL in yourrpcUrloption, you should be able to send contract metadata correctly over custom RPC.


Test and Verify

To make sure this fix resolves your issue, try rebuilding your Truffle project using the following command:

bash

truffle migrate --network mainnet

Then, connect to Metamask using the fullrpcUrloption:ws://localhost:7545/metadata`.

If you are still experiencing issues, please provide more details about your environment and the specific error messages you are seeing.

metamask ethereum site this