I am trying to create a Crowdfunding Dapp. I've deployed the smart contract on goerli testnet (link). Now I created the frontend using react and connected it to the contract using thirdweb.
The contract has a function createCampaign() which is pretty simple NOTE : there is a mapping called campaigns (mapping(uint256 => Campaign) public campaigns;) read the full source on the link above.
function createCampaign(
address _owner,
string memory _title,
string memory _description,
uint256 _target,
uint256 _deadline,
string memory _image
) public returns (uint256) {
Campaign storage campaign = campaigns[numberOfCampaigns];
require(
campaign.deadline < block.timestamp,
"The deadline should be a date in the future."
);
campaign.owner = _owner;
campaign.title = _title;
campaign.description = _description;
campaign.target = _target;
campaign.deadline = _deadline;
campaign.amountCollected = 0;
campaign.image = _image;
numberOfCampaigns++;
return numberOfCampaigns - 1;
}
in the frontend I've created component which renders a form to get the values. I've connected to the contract using thirdweb in this way
const { contract } = useContract(
"0x3A1e1F275E50810EE30b19517938D5d23a991802",
ABI
);
const { mutateAsync: createCampaign } = useContractWrite(
contract,
"createCampaign"
);
const address = useAddress();
const connect = useMetamask();
const publishCampaign = async (form) => {
console.log(`Address : ${address}`);
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);
}
};
this is being passed as context to that component so that I can use createCampaign() . in the component after the button press the code executed is
await createCampaign({
...form,
target: ethers.utils.parseUnits(form.target, 18),
});
when clicking the button I am getting an error which says "contract call failure Error: The address you're trying to send a transaction to is not a smart contract. Make sure you are on the correct network and the contract address is correct"
I read the documentation for thirdweb, cant seem to figure out.
I also saw this error. You need to set activeChain
in your ThirdwebProvider
to solve this.