1

I just started learning solidity and I am working on a bidding contract that allows bidders to bid on a campaign. I have a struct for campaigns. Bidders have details (address, name), I want to store bidders with their information inside of the campaign. There can be more than one bidder for a campaign

This is my Campaign and Bidder struct

struct Campaign {
    uint256 campaignID;
    uint256 budget;
    uint256 bidCount;

}
 struct Bidder {
    bool bided;
    uint256 bid;
    string name;
    address bidderAddress;

}
mapping(address => Bidder) public bidders;
Campaign[] public campaigns;

I wrote down a bid function here that takes the index of campaign and bid then populate bidCount.

function bid(uint256 _bidIndex, uint256 _twitterID) public {
    require(!bidders[msg.sender].bided);

    bidders[msg.sender].bid = _bidIndex;
    campaigns[_bidIndex].bidCount += 1;
    totalBids += 1;
}

So the Campaign can look something like this (if this is possible)

0: campaignID 1
1: budget 2ETH
2: bidCount 3
3: Bidder {0: name Bidder1, 1: address 0xahaaahha}
          {0: name Bidder2, 2: address 0x2334jddd}

Any help will be greatly appreciated. Thanks

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    May 25, 2022 at 13:03

1 Answer 1

0

Example of struct array within a struct...

There can be multiple ActionData structs in an Operation (like you might have bidders in a campaign)

interface IWallet {
    struct Operation {
        uint256 nonce;
        IWallet.ActionData[] actions;
    }

    struct ActionData {
        uint256 ethValue;
        address contractAddress;
        bytes encodedFunction;
    }
    ...
}

(https://github.com/web3well/bls-wallet/blob/main/contracts/contracts/interfaces/IWallet.sol#L9-L18)

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.