Can't call Mumbai contract

Hi,
I have a code like this

   const tokenContract = new ethers.Contract(nftaddress, NFT.abi, provider);
   const marketContract = new ethers.Contract(
   			nftmarketaddress,
   			Market.abi,
   			provider
   		);
   const data = await marketContract.fetchMarketItems();

that fails on calling smart contract deployed (successfully it seems) by hardhat. Weird is that it works just fine on ropsten (here on Infura via same provider) and I was able to get it running on Alchemy (on Mumbai). Any idea what could be wrong?

Polygon contracts are deployed at
0xBd770416a3345F91E4B34576cb804a576fa48EB1 and 0x5a443704dd4B594B382c22a083e2BD3090A6feF3

hi @vorcigernix, can you double-check the contract addresses, these don’t seem to be smart contracts on either mainnet or mumbai:

Thanks !

Correct. The contract address are somehow wrong. Not sure why though, this is hardhat config I am using:

		mumbai: {
			// Infura
			//url: `https://polygon-mumbai.infura.io/v3/f0671e059fde4ab1a541db0a8ea9aa1d`,
			url: `https://polygon-mumbai.g.alchemy.com/v2/elWZjOPfS0H03lYqe4-fSCu7LM4i7HUD`,
			accounts: [privateKey],
		},

Private key is same, when I comment out Alchemy and switch to Infura, I get wrong contract address, while there is no mention of any issue in response.

I don’t see how this could be an Infura issue, I’d into adding some debugging to understand what is the nftaddress and nftmarketaddress loaded when using the infura endpoint. How are you defining these contract addresses in your code ?

Also, since this is a public forum, please make sure you change the provider keys you’ve posted and keep them safe.

Thanks for response. I am changing ids, hopefully enough to not hit another working endpoint. Yes, I agree it is weird, I actually changed the provider connection several times before I tried Alchemy. This is relevant code:

		const provider = new ethers.providers.JsonRpcProvider("https://polygon-mumbai.g.alchemy.com/v2/id");
		//const provider = new ethers.providers.InfuraProvider("maticmum", {projectId: "id",projectSecret: "secret",});
		//const provider = new ethers.providers.JsonRpcProvider("https://polygon-mumbai.infura.io/v3/id");
		//const provider = new ethers.providers.InfuraProvider("maticmum", { projectId: "id",});
		//const provider = new ethers.providers.InfuraProvider("ropsten","id");

Only two of those works, ropsten on Infura and mumbai on Alchemy (I guess ropsten on Alchemy will work too). I think that the problem is probably with hardhat deployment, as the contract IDs seems to be invalid, but can’t figure out how (I don’t have much experience with hardhat though). This is the whole file:

require("@nomiclabs/hardhat-waffle");
const fs = require("fs");
const privateKey = process.env.privateKey || fs.readFileSync(".secret").toString().trim();
const infuraId = process.env.infuraId || fs.readFileSync(".infuraid").toString().trim();

module.exports = {
	defaultNetwork: "hardhat",
	networks: {
		hardhat: {
			chainId: 1337,
		},
		mumbai: {
			// Infura
			//url: `https://polygon-mumbai.infura.io/v3/${infuraId}`,
			url: `https://polygon-mumbai.g.alchemy.com/v2/${infuraId}`,
			accounts: [privateKey],
		},
		matic: {
			// Infura
			url: `https://polygon-mainnet.infura.io/v3/${infuraId}`,
			//url: "https://rpc-mainnet.maticvigil.com",
			accounts: [privateKey],
		},
		ropsten: {
			// Infura
			url: `https://ropsten.infura.io/v3/${infuraId}`,
			accounts: [privateKey],
		},
	},
	solidity: {
		version: "0.8.4",
		settings: {
			optimizer: {
				enabled: true,
				runs: 200,
			},
		},
	},
};

There is hardhat issue connected with this problem: https://github.com/nomiclabs/hardhat/issues/2162#issuecomment-1004600475

2 Likes

Haven’t found it before reporting here, thanks.