I'm working on the update campaign feature in a project.

First Issue - Prefilling the form fields

I want first to prefill the form fields then from there, a user can change what they want. In the /pages/UpdateCampaign page, I'm consoling the state and it returns all the fields. I've tried setting each item as the default so they will prefill but it's not working. Any ideas?

Second Issue - Updating the campaign instead of creating a new one.

Despite the data not prefilling, I decided to try out the update feature but instead of updating the campaign with its pID, it created a new campaign. I suspect it's an issue with the updateCampaign function in my web3/contracts/CrowdFunding.sol but can't seem to figure it out.

My Repo

1 Answer 1

  const updateCampaign = async (form) => {
    try {
      const data = await createCampaign({
        args: [
          // items have to be in the order they were the contract inside createCampaign()
          address, // owner of the campaign
          form.name, // name
          form.title, // title
          form.category, // campaign category
          form.description, // description
          new Date(form.deadline).getTime(),

      console.log("Contract call success!", data);
    } catch (error) {
      console.log("Contract call failed!", error);

This is the updateCampaign function in your client. It calls createCampaign on your contract.

  • 1
    Thanks for pointing that out. I'm however still stuck. When I log state in UpdateCampaign.jsx I get an object array with all the info. See Screenshot To get the value of an item, I'm trying state.item eg state.id but I'm getting "undefined". How do I access the data?
    – kihiuFrank
    Commented Aug 16, 2023 at 0:02
  • 1
    I figured it out. Everything works well now.
    – kihiuFrank
    Commented Aug 16, 2023 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.