import { ThirdwebProvider, metamaskWallet, coinbaseWallet, walletConnect, phantomWallet } from ' @thirdweb-dev/react';
import { createThirdwebClient, getContract, resolveMethod } from 'thirdweb';
import { defineChain } from 'thirdweb/chains';
import { StateContextProvider } from './context';
// Create the Thirdweb client with your clientId
const client = createThirdwebClient({
clientId: "bf783e8afe4c2547a9373fc7770da66e"
});
// Connect to your contract
const contract = getContract({
client,
chain: defineChain(137),
address: "0x20775d300BdE943Ac260995E977fb915fB01f399"
});
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<ThirdwebProvider
client={client}
supportedWallets={[
metamaskWallet({
recommended: true,
}),
coinbaseWallet(),
walletConnect(),
]}
activeChain={'polygon'}
clientId="bf783e8afe4c2547a9373fc7770da66e"
>
<Router>
<StateContextProvider contract_info={contract}>
<App />
</StateContextProvider>
</Router>
</ThirdwebProvider>
)
I have this code in my main.jsx. When i try const { contract } = useContract(contractAddress); in my stateContextProvider, i receive this error in my browser console.
console.js:273 Error: Could not fetch bytecode for contract at 0x20775d300BdE943Ac260995E977fb915fB01f399 on chain 137, double check that the address and chainId are correct.
at fetchContractMetadataFromBytecode (chunk-D5XVISX3.js?v=c52aa177:27087:11)
at async fetchContractMetadataFromAddress (chunk-D5XVISX3.js?v=c52aa177:27060:16)
The code below us the code for my StateContextProvider
export const StateContextProvider = ({ children, contract_info }) => {
console.log(contract_info.address);
console.log(contract_info.chain);
onsole.log(contract_info.client);
const contractAddress = contract_info.address
const { contract } = useContract(contractAddress);
const { mutateAsync: createCampaign } = useContractWrite(contract, 'createCampaign');
const address = useAddress(); //getting the address for our wallet
const publishCampaign = async (form) => {
try {
const data = await createCampaign([
address, // owner
form.title, // title
form.description, // description
form.target,
new Date(form.deadline).getTime(), // deadline,
form.image,
])
console.log("contract call success", data)
} catch (error) {
console.log("contract call failure", error)
}
}
return (
<StateContext.Provider
value={{
address,
contract,
createCampaign: publishCampaign,
}}
>
{children} //we have to render the children in between our context state provider
</StateContext.Provider>
)
}
I have confirmed that the contract address i have used is the right one from #thirdweb. I have also ensured the contractAddress is passed into my stateContextProvider by logging it to console. The code below is my stateContextprovider. I have confirmed that chain137 is my desired chain which is The Polygon network.
I do not expect to see that error, because of it,I cannot Create a Campaign succesfully.
civir zach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.