Here’s an article that addresses your problem with `Metamask'' custom RPC not sending correct contract information:
Problem with metamask custom RPC: fixed contract info
When migrating Truffle implementations to Metamask, it is common to encounter problems related to contract metadata. In this article, we will investigate the possible cause of incorrect contract ID being sent via customMetamaskRPC and provide steps to resolve the issue.
Problem: Incorrect contract metadata in custom RPC
In the Truffle configuration file (truffle-config.js), you set the
metamaskConfigoption with the following code:
module.exports = {
// ... other settings ...
metamaskConfig: {
host: 'localhost:7545',
port: 8545,
networkId: 1, // Set to default (main network)
public address: '',
rpcUrl: 'ws://localhost:7545', // Include the full RPC URL
},
};
As for setting the rpcUrloption, use the shortened version (
‘ws://localhost:7545 »), which is correct. However, when connecting to Metamask, the actual URL sent by the custom RPC will be a longer string, which includes the contract ID and network information.
Incorrect contract information in custom RPC
The problem arises because Truffle uses a specific format to send metadata (eg contracts) via web3 RPC. When using a short URL ('ws://localhost:7545''), the
rpcUrloption is used instead of the correct full URL.
Here's what happens:
- Short Form URL: Use a shortened URL that is suitable for Truffle.
- Full URL
: When you connect to Metamask using this short-form URL, it sends metadata via thews
protocol, where contract IDs are encoded in a specific format.
To work around this issue, make sure you use the correct full URL when setting therpcUrloption:
module.exports = {
// ... other settings ...
metamaskConfig: {
host: 'localhost:7545',
port : 8545,
networkId: 1, // Set to default (main network)
public address: '',
rpcUrl: 'ws://localhost:7545/metadata', // correct full URL
},
};
If you use the correct full URL in your rpcUrloption, you should be able to successfully send contract metadata via custom RPC.
Testing and Verifying
To make sure this solution will solve your problem, try rebuilding your Truffle project with the following command:
truffle migrants --main network
Then connect to Metamask with full option rpcUrl:
ws://localhost:7545/metadata`.
If you are still having problems, please provide more details about your environment and the specific error messages you are seeing.