English 中文(简体)
unable to get data from blockchain using thirdweb
原标题:

I am building a simple crowdfunding app using React and thirdweb , I was able to successfully create a Campaign mean data is pushed successfully , I have read docs everything works fine , but when i try to get data of Campaigns its show me nothing ,

ThirdWeb Provide a UI to directly call the contract from ui for testing purposes , I tried first creating a new event directly from thirdweb dashboard , but once uploaded , I invoke a getContract function supposed to give me data , but it show nothing just an empty array .

I followed a tutorial contract code looks fine

Here is my Contract Code :

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

contract CrowdFunding {
    constructor() {
        
    }

    struct Campaign {
        address  owner ;
        string title ;
        string description ;
        uint256 target;
        uint256 deadline;
        string image;
        uint256 amountCollected;
        address[] donators;
        uint256[] donations;
    }

    mapping(uint256 => Campaign) public campagins;

    uint256 public numberOFCampaigns = 0;


    function createCampaign (address _owner , string memory _title  , string memory _description , uint256 _target , uint256 _deadline , string memory _image )  public returns(uint256) {
        Campaign storage campaign = campagins[numberOFCampaigns] ;

        require(campaign.deadline <  block.timestamp , "Deadline must be Future Date" );

        campaign.owner = _owner;
        campaign.deadline = _deadline ;
        campaign.title = _title;
        campaign.description  =  _description;
        campaign.target = _target;
        campaign.image = _image;
        campaign.amountCollected = 0 ;

        numberOFCampaigns = numberOFCampaigns + 1 ;

        return numberOFCampaigns - 1;
    }

    function donateToCampaign(uint256 _id) public payable{
        uint256 amount  =  msg.value;

        Campaign storage campaign = campagins[_id];
        campaign.donators.push(msg.sender);
        campaign.donations.push(amount);

        (bool sent , ) = payable(campaign.owner).call{value : amount}("");

        if(sent){
            campaign.amountCollected = campaign.amountCollected +  amount;
        }
    }

    function getDonators(uint256 _id) public view returns (address[] memory , uint256[] memory) {
        return (campagins[_id].donators ,  campagins[_id].donations);
    }

    function getCampaign() public view returns (Campaign[] memory){
        Campaign[] memory allCampaigns = new Campaign[](numberOFCampaigns);

        for(uint i = 0 ; i < numberOFCampaigns ; i++){
            Campaign storage item =  campagins[i];

            allCampaigns[i] =  item;
        }

        return allCampaigns;
    }
}

I am totally beginner have no idea why it s throwing an empty array, If anyone can help kindly give a reference to docs or a little explanation what i am doing wrong .

问题回答

暂无回答




相关问题
unable to get data from blockchain using thirdweb

I am building a simple crowdfunding app using React and thirdweb , I was able to successfully create a Campaign mean data is pushed successfully , I have read docs everything works fine , but when i ...

How named accounts works in NEAR

It appears that named accounts in NEAR are being managed by the near and register smart contracts. However, this raises the question of whether NEAR natively supports named accounts. it s unclear if ...

ETH sendSignedTransaction

I Try to use @ethereumjs/tx to sign Transaction. I want to send ETH from one address to second address. .... const legacy = require( @ethereumjs/tx/dist/legacyTransaction ); const utils = require( ...

How to set a timer in solidity?

I am launching a game that should close after exactly 3 days/72 hours of initializing & deploying the contract. My current thoughts are: declare a variable, timestamp. in the constructor, set the ...

"code": -32000, "message": "execution reverted"

Hello I am trying to deploy a contract using remix.ethereum.org after linked the metamask account using mumbai network. I receive this error while making the transaction for the contract Gas ...

How to get all accounts from near protocol blockchain?

I am currently working on a program within the Near Protocol to generate user-specific Near token ownership statistics. However, I m not sure how to obtain a list of all user accounts. Is there an ...

热门标签