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
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
},
};
rpcUrl
Regarding setting the
option, 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.
'ws://localhost:7545'
Incorrect contract information in custom RPCThe problem arises because Truffle uses a specific format (e.g. contracts) to send metadata over web3 RPC. When you use a short-form URL (
), your
rpcUrloption is used instead of the correct full URL.
wsThis 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 theprotocol, where the contract IDs are encoded in a specific format.
rpcUrlTo fix the issue, make sure to use the correct full URL when setting your
option:
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
},
};
rpcUrl
By using the correct full URL in your
option, you should be able to send contract metadata correctly over custom RPC.
Test and VerifyTo 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.