0

i am working on a crowdsale type of smart contract and i want to store everyone who sent ether to my contract .So i created a struture like this

  struct User { 
    address participantsAddress;
    uint id;
    uint participantETHamount;
  } 

and my payable function like this :

  function invest() external payable {
 
    balanceOfContract=balanceOfContract+msg.value;
 
    mydata[id].participantETHamount = msg.value;
    mydata[id].participantsAddress = msg.sender;
    id++;

  }

but when I am debugging it, it seems like it doesn't store the values !!

1 Answer 1

0

use at own risk. because i don't have enough information.

Idk if you want to add the data to an array instead of mapping. and not sure if id is only a counter or a real generated Id. Also not sure if people can invest more than 1 time

pragma solidity 0.8.4;

contract ContractC1 {

    uint256 counter;
    uint256 balanceOfContract = 0;
    mapping (uint256 => User) public users;

    struct User { 
        address participantsAddress;
        uint256 participantETHamount;
    }

    function invest() external payable {
        balanceOfContract = balanceOfContract + msg.value;
        User memory user = User(msg.sender, msg.value);
        users[counter] = user;
        counter++;
    }
}
1
  • thank you for your answer it worked
    – dev
    May 17 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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