I am making a test biding system in solidity, and I have a problem. I want to make a list of bids for each tokenId.

struct Bid {
        bool hasBid;
        uint tokenId1;
        address bidder;
        uint value;

    mapping (uint => Bid) public Bids; 

function enterBidForNFT(uint Index, value) public virtual  {
        Bids[Index] = Bid(true, Index, msg.sender, value);

There are implementations where only the highest bid is stored, but I want all of the bids to be available and their corresponding addresses.

Any idea?

1 Answer 1


you can update your mapping to:

mapping (uint => Bid[]) public Bids;

and you don't need to have tokenId agian in your Bid struct when you have defined it in the mapping, for adding new bids your code should look like this:


and you can also have mapping for highestBidder so you can get track of who is the highest bidder and you can override it if new higher bid exist

struct HighestBid{uint256 value,address bidder};
    // tokenId -> highest bidder
mapping(uin256 => HighestBid) public highestBidder;

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.